UNPKG

authrix

Version:

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

87 lines (84 loc) 4.05 kB
export { a as authConfig, g as getAuthrixStatus, i as initAuth, b as isAuthrixInitialized } from './index-2c4aN9k6.js'; export { A as AuthDbAdapter, a as AuthUser } from './db-BIgxMgj8.js'; interface EnvironmentInfo { isNextJsAvailable: boolean; context: 'app-router' | 'pages-router' | 'middleware' | 'unknown'; hasAppRouterSupport: boolean; hasPagesRouterSupport: boolean; hasMiddlewareSupport: boolean; detectionComplete: boolean; runtimeInfo: { hasRequire: boolean; hasProcess: boolean; hasGlobalThis: boolean; hasNextData: boolean; nextRuntime?: string; }; } declare class CookieUtils { static getCookieName(): string; private static normalizeMaxAge; static createCookieString(name: string, value: string, options?: { maxAge?: number; expires?: Date; path?: string; secure?: boolean; sameSite?: 'strict' | 'lax' | 'none'; httpOnly?: boolean; }): string; static createLogoutCookie(name: string): string; /** * Normalize cookie options enforcing secure defaults: * - httpOnly defaults to true * - sameSite defaults to 'lax' * - secure defaults to true in production * - if sameSite === 'none', force secure true (browser requirement) * - path defaults to '/' */ private static normalizeOptions; } declare function checkAuthMiddleware(request: any, options?: { cookieName?: string; }): Promise<{ isAuthenticated: boolean; user: { id: any; email: any; createdAt: Date | undefined; } | null; reason: string; }>; declare function checkAuthMiddlewareSecure(request: any, options?: { validationEndpoint?: string; timeout?: number; cookieName?: string; }): Promise<{ isAuthenticated: boolean; user: any; reason: string; }>; declare function withAuth<T extends Record<string, any>, U extends Record<string, any>>(handler: (req: T & { user: any; }, res: U) => Promise<void> | void): (req: T, res: U) => Promise<any>; declare function createSignupHandler(): (request: Request) => Promise<Response>; declare function createSigninHandler(): (request: Request) => Promise<Response>; declare function createLogoutHandler(): (request: Request) => Promise<Response>; declare function createCurrentUserHandler(): (request: Request) => Promise<Response>; declare function createTokenValidationHandler(): (request: Request) => Promise<Response>; declare function createSignupHandlerPages(): (req: any, res: any) => Promise<any>; declare function createSigninHandlerPages(): (req: any, res: any) => Promise<any>; declare function createLogoutHandlerPages(): (req: any, res: any) => Promise<any>; declare function createCurrentUserHandlerPages(): (req: any, res: any) => Promise<any>; declare function createTokenValidationHandlerPages(): (req: any, res: any) => Promise<any>; declare function getNextJsEnvironmentInfo(): EnvironmentInfo; declare function redetectNextJsEnvironment(): EnvironmentInfo; declare function resetEnvironmentDetection(): void; declare function forceNextJsAvailability(available?: boolean): void; declare function createAuthCookieString(token: string, options?: Partial<Parameters<typeof CookieUtils.createCookieString>[2]>): string; declare function createLogoutCookieString(): string; declare function createAuthenticatedResponse(data: any, token?: string, options?: { status?: number; headers?: Record<string, string>; cookieOptions?: any; }): Response; export { checkAuthMiddleware, checkAuthMiddlewareSecure, createAuthCookieString, createAuthenticatedResponse, createCurrentUserHandler, createCurrentUserHandlerPages, createLogoutCookieString, createLogoutHandler, createLogoutHandlerPages, createSigninHandler, createSigninHandlerPages, createSignupHandler, createSignupHandlerPages, createTokenValidationHandler, createTokenValidationHandlerPages, forceNextJsAvailability, getNextJsEnvironmentInfo, redetectNextJsEnvironment, resetEnvironmentDetection, withAuth };