UNPKG

@tag0/react-auth

Version:

Customizable AuthService/AuthProvider and components for react

50 lines (49 loc) 1.88 kB
/// <reference types="react" /> import { PropsWithChildren } from "react"; interface LoginPropsType { email: string; password: string; captchaToken?: string; } interface RegisterPropsType extends LoginPropsType { firstName: string; lastName: string; birthDate: number; } interface CaptchaOptions { enabled: boolean; maxFailureCount: number; siteKey: string; } interface AuthProviderPropsType { isAuthenticated?: () => boolean; login?: (props: LoginPropsType, context?: AuthProviderType) => Promise<any>; logout?: (context?: AuthProviderType) => Promise<any>; register?: (props: RegisterPropsType, context?: AuthProviderType) => Promise<any>; resetPassword?: (props: { email: string; captchaToken?: string; }, context?: AuthProviderType) => Promise<any>; changePassword?: (props: { password: string; token: string; }, context?: AuthProviderType) => Promise<any>; activate?: (props: { token: string; }, context?: AuthProviderType) => Promise<any>; modules?: any; options?: any; messageProvider?: any; captchaOptions?: CaptchaOptions; } interface AuthProviderType extends AuthProviderPropsType { getModulePath: (module: string) => string; setToken?: (token: string | null) => any; notify?: any; token?: string | null; } declare const useAuth: () => AuthProviderType; declare const AuthProvider: ({ login, logout, register, resetPassword, changePassword, activate, isAuthenticated: overrideIsAuthenticated, options: authOptions, modules: authModules, messageProvider, captchaOptions, children }: PropsWithChildren<AuthProviderPropsType>) => JSX.Element; declare const AuthRouter: () => JSX.Element; declare const SecureRoute: ({ children, ...props }: any) => JSX.Element; export { AuthProvider, AuthRouter, SecureRoute, useAuth };