sessionize-auth
Version:
A flexible session management library for React, Next.js, Angular, and React Native
44 lines (38 loc) • 994 B
text/typescript
/**
* Core types for sessionize-auth
*/
export interface SessionStore<T = any> {
get(): T | null;
set(account: T): void;
remove(): void;
}
export interface SessionManager<T = any> {
account: T | null;
startSession(account: T): void;
closeSession(): void;
isAuthenticated(): boolean;
}
export interface AuthConfig<T = any> {
storageType?: "localStorage" | "sessionStorage" | "cookies";
accountType?: T;
redirectPath?: string;
returnToParam?: string;
storageKey?: string;
}
export interface AuthAdapter<T = any> {
withAuth: <P extends object>(
Component: React.ComponentType<P>,
config?: AuthConfig<T>
) => React.ComponentType<P>;
useAuth: () => {
account: T | null;
isAuthenticated: boolean;
startSession: (account: T) => void;
closeSession: () => void;
login: (account: T, returnTo?: string) => void;
};
}
export interface ReturnToState {
returnTo?: string;
timestamp?: number;
}