@disruptph/react-auth-context
Version:
A generic react auth context
26 lines (25 loc) • 787 B
TypeScript
import React, { FC } from 'react';
export interface AuthService {
loginWithEmail: <T>(email: string, password: string) => Promise<T>;
checkAuth: <T>() => Promise<T | null>;
logout: () => Promise<void>;
}
declare type User = unknown;
interface State {
user: User | null;
isLoggedIn: boolean;
isLoggingIn: boolean;
}
interface Actions {
loginWithEmail: (email: string, password: string) => Promise<void>;
logout: () => Promise<void>;
}
export declare const AuthContext: React.Context<State & Actions>;
export declare const AuthConsumer: React.Consumer<State & Actions>;
export declare const useAuth: () => State & Actions;
interface Props {
service: AuthService;
children: React.ReactNode;
}
export declare const AuthProvider: FC<Props>;
export {};