| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- ---
- title: "UseAuth"
- generated: true
- ---
- <GenerationInfo sourceFile="packages/dashboard/src/lib/hooks/use-auth.tsx" sourceLine="15" packageName="@vendure/dashboard" since="3.3.0" />
- Provides access to the [AuthContext](/reference/dashboard/hooks/use-auth#authcontext) which contains information
- about the active channel.
- ```ts title="Signature"
- function useAuth(): void
- ```
- <GenerationInfo sourceFile="packages/dashboard/src/lib/providers/auth.tsx" sourceLine="17" packageName="@vendure/dashboard" since="3.3.0" />
- Provides information about the current user & their authentication & authorization
- status.
- ```ts title="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;
- }
- ```
- <div className="members-wrapper">
- ### status
- <MemberInfo kind="property" type={`'initial' | 'authenticated' | 'verifying' | 'unauthenticated'`} />
- The status of the authentication.
- ### authenticationError
- <MemberInfo kind="property" type={`string`} />
- The error message if the authentication fails.
- ### isAuthenticated
- <MemberInfo kind="property" type={`boolean`} />
- Whether the user is authenticated.
- ### login
- <MemberInfo kind="property" type={`(username: string, password: string, onSuccess?: () => void) => void`} />
- The function to login the user.
- ### logout
- <MemberInfo kind="property" type={`(onSuccess?: () => void) => Promise<void>`} />
- The function to logout the user.
- ### user
- <MemberInfo kind="property" type={`ResultOf<typeof CurrentUserQuery>['activeAdministrator'] | undefined`} />
- The user object.
- ### channels
- <MemberInfo kind="property" type={`NonNullable<ResultOf<typeof CurrentUserQuery>['me']>['channels'] | undefined`} />
- The channels object.
- ### refreshCurrentUser
- <MemberInfo kind="property" type={`() => void`} />
- The function to refresh the current user.
- </div>
|