Skip to main content
The UserInfo type represents the authenticated user’s session information, including their profile, organization context, and permissions.

Type definition

interface UserInfo {
  user: User;
  sessionId: string;
  organizationId?: string;
  role?: string;
  roles?: string[];
  permissions?: string[];
  entitlements?: string[];
  featureFlags?: string[];
  impersonator?: Impersonator;
  accessToken: string;
}

Properties

user
User
required
The authenticated user object from WorkOS. Contains user profile information such as email, name, and other user attributes.
sessionId
string
required
The unique identifier for the user’s session.
organizationId
string
The ID of the organization the user is currently authenticated with, if applicable.
role
string
The user’s primary role within the organization.
roles
string[]
An array of all roles assigned to the user within the organization.
permissions
string[]
An array of permissions granted to the user based on their roles.
entitlements
string[]
An array of entitlements available to the user.
featureFlags
string[]
An array of feature flags enabled for the user.
impersonator
Impersonator
Information about the admin user who is impersonating this user, if applicable. See Impersonator for details.
accessToken
string
required
The JWT access token for the authenticated session.

Usage

The UserInfo type is returned by the withAuth function when a user is authenticated:
import { withAuth } from '@workos-inc/authkit-nextjs';

export default async function Page() {
  const { user, sessionId, organizationId, roles } = await withAuth();

  if (!user) {
    return <div>Not authenticated</div>;
  }

  return (
    <div>
      <h1>Welcome, {user.firstName}!</h1>
      <p>Session ID: {sessionId}</p>
      {organizationId && <p>Organization: {organizationId}</p>}
      {roles && <p>Roles: {roles.join(', ')}</p>}
    </div>
  );
}
  • Session - The underlying session data structure
  • NoUserInfo - Type for unauthenticated users

NoUserInfo

When a user is not authenticated, the NoUserInfo type is returned instead:
interface NoUserInfo {
  user: null;
  sessionId?: undefined;
  organizationId?: undefined;
  role?: undefined;
  roles?: undefined;
  permissions?: undefined;
  entitlements?: undefined;
  featureFlags?: undefined;
  impersonator?: undefined;
  accessToken?: undefined;
}
This type ensures that all properties are explicitly undefined when no user is authenticated, making it type-safe to check for authentication by testing the user property.

Build docs developers (and LLMs) love