Skip to content

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>
}
TypeDescription
Principal | nullThe current user’s Principal, or null if not authenticated.