Skip to content

useIdentity

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>
}
function useIdentity(): UseIdentityResult

Takes no parameters. Reads from the XNetProvider context.

FieldTypeDescription
identityIdentity | nullThe full Identity object from XNetProvider config, or null.
isAuthenticatedbooleantrue if either identity or authorDID is set.
didstring | nullThe user’s DID. Resolved from identity.did first, then authorDID.
const { did } = useIdentity()
const { remoteUsers } = useNode(PageSchema, pageId, { did: did ?? undefined })
const { isAuthenticated } = useIdentity()
if (!isAuthenticated) {
return <OnboardingFlow />
}
return <AppContent />