import { AuthActions, AuthState } from '@frontegg/redux-store'; import { RedirectOptions } from '@frontegg/rest-api'; import { AuthPageRoutes, User } from '@frontegg/redux-store'; export type AuthMapper = { state: (state: AuthState) => any; actions: (actions: AuthActions) => any; }; export type AuthStateMapper = (state: AuthState) => S; /** * Use this `frontegg` hook function to obtain the complete authentication state, if it exists. * * ```jsx * export const MyFunctionComponent = () => { * const { isAuthenticated, user } = useAuth(); * * return isAuthenticated ?
Hello, User {user.name}
: null; * } * ``` * * You can also utilize other `frontegg` hooks like `useAuthUser` to specifically retrieve the user and redirect to the login page if necessary, `useAuthUserOrNull` to get the user if available, and `useIsAuthenticated` for checking authentication status. */ export declare function useAuth(): AuthState; export declare function useAuth(stateMapper: AuthStateMapper): S; export declare function useAuthState(): AuthState; /** * ```jsx * export const MyFunctionComponent = () => { * const { isAuthenticated, user } = useAuth(); * const loginWithRedirect = useLoginWithRedirect(); * * if (!isAuthenticated) { * loginWithRedirect(); * return <>; * } * * return (
Hello User {user.name}
); * } * ``` * /** * Use this frontegg hook function to redirect the user to the login page when in hosted login mode. * If the user is already authenticated, this method will direct the user to the store, and you can retrieve user information using the `useAuthUserOrNull` method. * * To ensure the user is available on the first page load when authenticated, configure this option in your `FronteggProvider`: * `authOptions`: * `hostedLoginOptions`: * `loadUserOnFirstLoad: true` * * When using this option, you can have the user on the first load, and you can control when the user is redirected to the login page by using `loginWithRedirect`. */ export declare const useLoginWithRedirect: () => (additionalParams?: Record) => Promise; export declare const useLoginWithRedirectV2: () => (payload?: { additionalParams?: Record; shouldRedirectToLogin?: boolean; firstTime?: boolean; loginDirectAction?: import("dist/@frontegg/redux-store/auth/LoginState/interfaces").LoginDirectAction; }) => Promise; export declare const useAuthActions: () => AuthActions; export declare const useOnRedirectTo: () => ((path: string, opts?: RedirectOptions) => void); export declare const useAuthRoutes: () => AuthPageRoutes; /** * ```jsx * export const MyFunctionComponent = () => { * const isAuthenticated = useIsAuthenticated(); * return isAuthenticated ?
Hello User
: * } * ``` * * use this frontegg hook function to get if user is "Authenticated" */ export declare const useIsAuthenticated: () => boolean; /** * ```jsx * export const MyFunctionComponent = () => { * const user = useAuthUser(); * return user ?
Hello {user.name}!
:
Hello Guest!
* } * ``` * * Use this `frontegg` hook function to obtain the authenticated user. * If the user is not authenticated, this method will immediately redirect the user to the login page. * To prevent this immediate redirection behavior, use the `useAuthUserOrNull` method. */ export declare const useAuthUser: () => User; /** * ```jsx * export const MyFunctionComponent = () => { * const user = useAuthUserOrNull(); * return user ?
Hello {user.name}!
:
Hello Guest!
* } * ``` * * Use this `frontegg` hook function to retrieve the authenticated user. If the user is not authenticated, this hook will return null. To redirect the user to the login page in case they are not authenticated, use the `useAuthUser` method. */ export declare const useAuthUserOrNull: () => User | null; export declare const useStoreActions: () => import("@frontegg/redux-store").FronteggActions;