UNPKG

authrix

Version:

Lightweight, flexible authentication library for Node.js and TypeScript.

112 lines (109 loc) 3.36 kB
export { a as authConfig, g as getAuthrixStatus, i as initAuth, b as isAuthrixInitialized } from './index-BpFSCakw.cjs'; export { A as AuthDbAdapter, a as AuthUser } from './db-R-GJxQGc.cjs'; interface CookieOptions { httpOnly?: boolean; secure?: boolean; maxAge?: number; sameSite?: "strict" | "lax" | "none"; path?: string; expires?: Date; } interface AuthResult { user: { id: string; email: string; }; token: string; cookieOptions: CookieOptions; } interface AuthErrorResult { success: false; error: { message: string; }; } type AuthResponse = AuthResult | AuthErrorResult; interface LogoutResult { cookieName: string; cookieOptions: CookieOptions; message: string; } /** * Framework-agnostic signup function * Returns user data, token, and cookie options for manual handling */ declare function signupUniversal(email: string, password: string): Promise<AuthResponse>; /** * Framework-agnostic signin function * Returns user data, token, and cookie options for manual handling */ declare function signinUniversal(email: string, password: string): Promise<AuthResponse>; /** * Framework-agnostic logout function * Returns cookie information for manual clearing */ declare function logoutUniversal(): LogoutResult; /** * Get current user from token (framework-agnostic) */ declare function getCurrentUserUniversal(token: string | null): Promise<{ id: string; email: string; createdAt: Date | undefined; } | null>; /** * Check if token is valid (framework-agnostic) */ declare function isTokenValidUniversal(token: string | null): Promise<boolean>; /** * Utility to create a standard cookie string */ declare function createCookieString(name: string, value: string, options: CookieOptions): string; /** * Utility to parse cookies from a cookie header string */ declare function parseCookies(cookieHeader: string): Record<string, string>; /** * Get auth token from parsed cookies */ declare function getAuthTokenFromCookies(cookies: Record<string, string>): string | null; /** * Validate authentication for any framework * Returns both validation result and user data */ declare function validateAuth(token: string | null): Promise<{ isValid: boolean; user: null; error: string; } | { isValid: boolean; user: { id: string; email: string; createdAt: Date | undefined; }; error: null; }>; /** * Create authentication headers for API requests */ declare function createAuthHeaders(token: string): Record<string, string>; /** * Utility for framework-specific implementations to handle errors consistently */ declare function createAuthError(message: string, status?: number): { success: boolean; error: { message: string; }; status: number; }; /** * Utility for framework-specific implementations to handle success responses consistently */ declare function createAuthSuccess<T>(data: T, status?: number): { success: boolean; data: T; status: number; }; export { type AuthResult, type CookieOptions, type LogoutResult, createAuthError, createAuthHeaders, createAuthSuccess, createCookieString, getAuthTokenFromCookies, getCurrentUserUniversal, isTokenValidUniversal, logoutUniversal, parseCookies, signinUniversal, signupUniversal, validateAuth };