ysd-jwt
Version:
A lightweight and beginner-friendly JWT authentication middleware for Express.js with token creation, verification, and user extraction from headers or cookies.
17 lines (16 loc) • 546 B
TypeScript
import { Request, RequestHandler } from 'express';
export interface JwtMiddlewareOptions {
secret?: string;
publicKey?: string | Buffer;
algorithm?: 'HS256' | 'RS256';
issuer?: string;
audience?: string | string[];
clockToleranceSec?: number;
getToken?: (req: Request) => string | null;
}
/**
* Express middleware to verify JWT and attach payload to req.user
* @param opts - Middleware options
* @returns Express RequestHandler
*/
export declare function jwtMiddleware(opts: JwtMiddlewareOptions): RequestHandler;