useIdentity
Quick example
Section titled “Quick example”import { useIdentity } from '@xnet/react'
function UserBadge() { const { did, isAuthenticated } = useIdentity()
if (!isAuthenticated) return <p>Not signed in</p> return <p>Signed in as {did?.slice(0, 20)}...</p>}Signature
Section titled “Signature”function useIdentity(): UseIdentityResultTakes no parameters. Reads from the XNetProvider context.
Return value
Section titled “Return value”| Field | Type | Description |
|---|---|---|
identity | Identity | null | The full Identity object from XNetProvider config, or null. |
isAuthenticated | boolean | true if either identity or authorDID is set. |
did | string | null | The user’s DID. Resolved from identity.did first, then authorDID. |
Usage patterns
Section titled “Usage patterns”Pass DID to useNode for presence
Section titled “Pass DID to useNode for presence”const { did } = useIdentity()const { remoteUsers } = useNode(PageSchema, pageId, { did: did ?? undefined })Conditional rendering
Section titled “Conditional rendering”const { isAuthenticated } = useIdentity()
if (!isAuthenticated) { return <OnboardingFlow />}return <AppContent />Gotchas
Section titled “Gotchas”Related
Section titled “Related”useNode— passdidfor presence awareness- Identity guide — generating and managing key pairs