Safe version of useIdentity that returns null outside of an IdentityProvider.
useIdentity
null
IdentityProvider
Useful for components that optionally integrate with identity — for example, a header component that shows user info when auth is available but still renders without it.
The IdentityContextValue, or null if no provider is found.
function Header() { const identity = useIdentitySafe(); return ( <header> {identity?.isAuthenticated ? <span>{identity.user?.email}</span> : <a href="/login">Sign In</a>} </header> );} Copy
function Header() { const identity = useIdentitySafe(); return ( <header> {identity?.isAuthenticated ? <span>{identity.user?.email}</span> : <a href="/login">Sign In</a>} </header> );}
Safe version of
useIdentitythat returnsnulloutside of anIdentityProvider.Useful for components that optionally integrate with identity — for example, a header component that shows user info when auth is available but still renders without it.