Skip to main content
Docs

useAuth()

The useAuth() hook provides access to the current user's authentication state and methods to manage the active session.

Note

To access auth data server-side, see the .

Example

The following example demonstrates how to use the useAuth() hook to access the current auth state, like whether the user is signed in or not. It also includes a basic example for using the getToken() method to retrieve a session token for fetching data from an external resource.

Returns

  • Name
    actor
    Type
    undefined
    Description

    The JWT actor for the session. Holds identifier for the user that is impersonating the current user. Read more about impersonation.

  • Name
    getToken
    Type
    GetToken
    Description

    A function that retrieves the current user's session token or a custom JWT template. Returns a promise that resolves to the token. See the .

  • Name
    has
    Type
    { }
    Description

    A function that checks if the user has specific permissions or roles. See the .

  • Name
    isLoaded
    Type
    false
    Description

    A boolean that indicates whether Clerk has completed initialization. Initially false, becomes true once Clerk loads.

  • Name
    isSignedIn
    Type
    undefined
    Description

    A boolean that indicates whether a user is currently signed in.

  • Name
    orgId
    Type
    undefined
    Description

    The ID of the user's active organization.

  • Name
    orgRole
    Type
    undefined
    Description

    The current user's role in their active organization.

  • Name
    orgSlug
    Type
    undefined
    Description

    The URL-friendly identifier of the user's active organization.

  • Name
    sessionClaims
    Type
    undefined
    Description

    The current user's session claims.

  • Name
    sessionId
    Type
    undefined
    Description

    The ID for the current session.

  • Name
    signOut
    Type
    SignOut
    Description

    A function that signs out the current user. Returns a promise that resolves when complete. See the .

  • Name
    userId
    Type
    undefined
    Description

    The ID of the current user.

NameType
actornull
getTokenGetToken
has()(params: CheckAuthorizationParamsWithCustomPermissions) => false
isLoadedtrue
isSignedInfalse
orgIdnull
orgRolenull
orgSlugnull
sessionClaimsnull
sessionIdnull
signOutSignOut
userIdnull
NameType
actorActClaim | null
getTokenGetToken
hasCheckAuthorizationWithCustomPermissions
isLoadedtrue
isSignedIntrue
orgIdnull
orgRolenull
orgSlugnull
sessionClaimsJwtPayload
sessionIdstring
signOutSignOut
userIdstring
NameType
actorActClaim | null
getTokenGetToken
hasCheckAuthorizationWithCustomPermissions
isLoadedtrue
isSignedIntrue
orgIdstring
orgRoleOrganizationCustomRoleKey
orgSlugstring | null
sessionClaimsJwtPayload
sessionIdstring
signOutSignOut
userIdstring

Parameters

Feedback

What did you think of this content?

Last updated on