UNPKG

fastapi-rtk

Version:

A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.

91 lines (90 loc) 2.43 kB
export function useAuth(options: SafeContextOptions): AuthContext; export type SafeContextOptions = { /** * - Whether to throw an error if the context is not provided. */ throwOnError?: boolean; /** * - The default value to return if the context is not provided. */ defaultValue?: any; }; export type AuthUser = { /** * - The unique identifier of the authenticated user. */ id: number; /** * - The username of the authenticated user. */ username: string; /** * - The email of the authenticated user. */ email: string; /** * - The first name of the authenticated user. */ first_name: string; /** * - The last name of the authenticated user. */ last_name: string; /** * - Indicates whether the user account is active. */ is_active: boolean; /** * - An array of permissions assigned to the user. */ permissions: string[]; /** * - An array of roles assigned to the user. */ roles: string[]; }; export type AuthContext = { /** * - The authenticated user object, or null if not authenticated. */ user: AuthUser | null; /** * - Indicates whether the authentication state is currently loading. */ loading: boolean; /** * - An error object if the authentication request failed. */ error: { message: string; originalError: Error; } | null; /** * - A function to sign in the user with a username and password. */ signin: (username: string, password: string) => Promise<void>; /** * - A function to sign out the user. */ signout: () => Promise<void>; /** * - A function to update the authenticated user's data. */ update: (data: Record<string, any>) => Promise<AuthUser>; /** * - A function to reset the user's password. */ resetPassword: (password: string) => Promise<void>; /** * - A function to sign in the user using OAuth with a specified provider. If `popup` is true, it opens a popup window for the OAuth flow. */ oauth_signin: (provider: string, popup?: boolean) => Promise<void>; /** * - A function to refetch the authenticated user's data. */ refetch: () => Promise<void>; /** * - A function to reset the error state. */ resetError: () => void; };