Skip to main content

UseAuth

useAuth

Provides access to the AuthContext which contains information about the active channel.

Signature
function useAuth(): void

AuthContext

Provides information about the current user & their authentication & authorization status.

Signature
interface AuthContext {
status: 'initial' | 'authenticated' | 'verifying' | 'unauthenticated';
authenticationError?: string;
isAuthenticated: boolean;
login: (username: string, password: string, onSuccess?: () => void) => void;
logout: (onSuccess?: () => void) => Promise<void>;
user: ResultOf<typeof CurrentUserQuery>['activeAdministrator'] | undefined;
channels: NonNullable<ResultOf<typeof CurrentUserQuery>['me']>['channels'] | undefined;
refreshCurrentUser: () => void;
}

status

property
'initial' | 'authenticated' | 'verifying' | 'unauthenticated'

The status of the authentication.

authenticationError

property
string

The error message if the authentication fails.

isAuthenticated

property
boolean

Whether the user is authenticated.

login

property
(username: string, password: string, onSuccess?: () => void) => void

The function to login the user.

logout

property
(onSuccess?: () => void) => Promise<void>

The function to logout the user.

user

property
ResultOf<typeof CurrentUserQuery>['activeAdministrator'] | undefined

The user object.

channels

property
NonNullable<ResultOf<typeof CurrentUserQuery>['me']>['channels'] | undefined

The channels object.

refreshCurrentUser

property
() => void

The function to refresh the current user.