UNPKG

@mussnad/frappe-react-query

Version:
34 lines (33 loc) 1.35 kB
import { AuthCredentials, AuthResponse, FrappeError, FrappeAuthConfig } from '../types'; interface FrappeAuthReturn { currentUser: string | null | undefined; isLoading: boolean; isFetching: boolean; error: FrappeError | null | undefined; login: (credentials: AuthCredentials) => Promise<AuthResponse>; logout: () => Promise<void>; updateCurrentUser: () => void; getUserCookie: () => void; authResponse?: AuthResponse; } /** * Hook to start listening to user state and provides functions to login/logout * * @param options - [Optional] React Query configuration options for fetching current logged in user * @param configs - [Optional] Additional configurations for the auth hook * * @returns Returns an object with the following properties: currentUser, loading, error, and functions to login, logout and updateCurrentUser * * @example * * const { currentUser, isLoading, isFetching, error, login, logout, updateCurrentUser, getUserCookie } = useFrappeAuth() * With configs: * const { currentUser, isLoading, isFetching, error, login, logout, updateCurrentUser, getUserCookie } = useFrappeAuth( * {}, * { * userCheckMethod: 'frappe.auth.get_logged_user', * }, * ) */ export declare const useFrappeAuth: (options?: any, configs?: FrappeAuthConfig) => FrappeAuthReturn; export {};