use-auth.mdx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. title: "UseAuth"
  3. generated: true
  4. ---
  5. <GenerationInfo sourceFile="packages/dashboard/src/lib/hooks/use-auth.tsx" sourceLine="15" packageName="@vendure/dashboard" since="3.3.0" />
  6. Provides access to the [AuthContext](/reference/dashboard/hooks/use-auth#authcontext) which contains information
  7. about the active channel.
  8. ```ts title="Signature"
  9. function useAuth(): void
  10. ```
  11. <GenerationInfo sourceFile="packages/dashboard/src/lib/providers/auth.tsx" sourceLine="17" packageName="@vendure/dashboard" since="3.3.0" />
  12. Provides information about the current user & their authentication & authorization
  13. status.
  14. ```ts title="Signature"
  15. interface AuthContext {
  16. status: 'initial' | 'authenticated' | 'verifying' | 'unauthenticated';
  17. authenticationError?: string;
  18. isAuthenticated: boolean;
  19. login: (username: string, password: string, onSuccess?: () => void) => void;
  20. logout: (onSuccess?: () => void) => Promise<void>;
  21. user: ResultOf<typeof CurrentUserQuery>['activeAdministrator'] | undefined;
  22. channels: NonNullable<ResultOf<typeof CurrentUserQuery>['me']>['channels'] | undefined;
  23. refreshCurrentUser: () => void;
  24. }
  25. ```
  26. <div className="members-wrapper">
  27. ### status
  28. <MemberInfo kind="property" type={`'initial' | 'authenticated' | 'verifying' | 'unauthenticated'`} />
  29. The status of the authentication.
  30. ### authenticationError
  31. <MemberInfo kind="property" type={`string`} />
  32. The error message if the authentication fails.
  33. ### isAuthenticated
  34. <MemberInfo kind="property" type={`boolean`} />
  35. Whether the user is authenticated.
  36. ### login
  37. <MemberInfo kind="property" type={`(username: string, password: string, onSuccess?: () => void) => void`} />
  38. The function to login the user.
  39. ### logout
  40. <MemberInfo kind="property" type={`(onSuccess?: () => void) => Promise<void>`} />
  41. The function to logout the user.
  42. ### user
  43. <MemberInfo kind="property" type={`ResultOf<typeof CurrentUserQuery>['activeAdministrator'] | undefined`} />
  44. The user object.
  45. ### channels
  46. <MemberInfo kind="property" type={`NonNullable<ResultOf<typeof CurrentUserQuery>['me']>['channels'] | undefined`} />
  47. The channels object.
  48. ### refreshCurrentUser
  49. <MemberInfo kind="property" type={`() => void`} />
  50. The function to refresh the current user.
  51. </div>