useAuth()
The useAuth() hook is a convenient way to access the current auth state. This hook provides the minimal information needed for data-loading and helper methods to manage the current active session.
useAuth() returns
isSignedIn boolean
A boolean that returns true if the user is signed in.
isLoaded boolean
A boolean that until OneAuxilia loads and initializes, will be set to false. Once OneAuxilia loads, isLoaded will be set to true.
userId string
The current user's ID.
sessionId string
The current user's session ID.
orgId string
The current user's active organization ID.
orgRole string
The current user's active organization role.
orgSlug string
The current user's organization slug.
signOut() (options?: SignOutOptions) => Promise<void>
A function that signs the user out. See the reference documentation for more information.
getToken() (options?: GetTokenOptions) => Promise<string | null>
A function that returns a promise that resolves to the current user's session token. Can also be used to retrieve a custom JWT template. See the reference documentation for more information.
has() (isAuthorizedParams: CheckAuthorizationParamsWithCustomPermissions) => boolean
A function that returns a boolean based on the permission or role provided as parameter. Can be used for authorization. See the reference documentation for more information.
How to use the useAuth() hook
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 demonstrates a basic example of how you could use the getToken() method to retrieve a session token for fetching data from an external resource.
Last updated