UNPKG

authrix

Version:

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

23 lines (20 loc) 752 B
import { Request, Response, NextFunction } from 'express'; /** * Framework-agnostic authentication middleware * Can be used with Express, Fastify, Koa, etc. */ declare function createAuthMiddleware(options?: { required?: boolean; tokenExtractor?: (req: any) => string | null; errorHandler?: (error: any, req: any, res: any, next?: any) => void; }): (req: any, res: any, next: any) => Promise<void>; /** * Express.js optional auth middleware * Adds user info if available, but doesn't require authentication */ declare function optionalAuthMiddleware(req: Request & { user?: any; auth?: any; isAuthenticated?: boolean; }, res: Response, next: NextFunction): void; export { createAuthMiddleware, optionalAuthMiddleware };