Skip to main content

Documentation Index

Fetch the complete documentation index at: https://iam-docs.razi.ai/llms.txt

Use this file to discover all available pages before exploring further.

Overview

useSession hook is used to access the current session and user details from the SessionContext.

Example Usage

session-component.tsx
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

isSignedIn
boolean
boolean indicating whether the user is signed in.
session
Session | undefined
current session object.
Session type
type Session = {
  sessionId: string;
  sessionToken: string;
  userId: string;
};
userDetails
UserDetails | undefined
details of the currently signed-in user.
UserDetails type
type UserDetails = {
  firstName: string;
  lastName: string;
  phoneNumber: string;
  email: string;
  isEmailVerified: boolean;
  isPhoneVerified: boolean;
  userState: string;
  displayName: string;
  metadata?: Record<string, string>;
};