useUserPrincipal
useUserPrincipal is a convenience hook that returns the current user’s Principal or null.
import { useUserPrincipal } from "./reactor/hooks"
function UserBadge() { const principal = useUserPrincipal()
if (!principal) return null if (principal.isAnonymous()) return <span>Anonymous</span>
return <span>{principal.toText().slice(0, 12)}...</span>}Return Value
Section titled “Return Value”| Type | Description |
|---|---|
Principal | null | The current user’s Principal, or null if not authenticated. |
See Also
Section titled “See Also”- createAuthHooks — Auth hooks factory
- useAuth — Main auth hook