useUserPrincipal
useUserPrincipal is a convenience hook that returns the signed-in user’s
Principal, or null while signed out. A signed-out session still holds an
anonymous identity, and the hook does not return its principal.
import { useUserPrincipal } from "./reactor/hooks"
function UserBadge() { const principal = useUserPrincipal()
if (!principal) return <span>Signed out</span>
return <span>{principal.toText().slice(0, 12)}...</span>}Return Value
Section titled “Return Value”| Type | Description |
|---|---|
Principal | null |
The signed-in user’s Principal, or null while signed out. |
See Also
Section titled “See Also”- createAuthHooks — Auth hooks factory
- useAuth — Main auth hook