Overview
useSession hook is used to access the current session and user details from the SessionContext.
Example Usage
import { useSession } from '@locai1/iam-react';
const SIGN_IN_PAGE = "/sign-in";
const Header = () => {
const { isSignedIn } = useSession();
return (
<header>
{isSignedIn && (
<button>
Sign Out
</button>
)}
{!isSignedIn && (
<Link href={SIGN_IN_PAGE}>
Sign In
</Link>
)}
</header>
);
};
Returns
boolean indicating whether the user is signed in.
current session object.type Session = {
sessionId: string;
sessionToken: string;
userId: string;
};
details of the currently signed-in user.type UserDetails = {
firstName: string;
lastName: string;
phoneNumber: string;
email: string;
isEmailVerified: boolean;
isPhoneVerified: boolean;
userState: string;
displayName: string;
metadata?: Record<string, string>;
};