28 lines
1.5 KiB
TypeScript
28 lines
1.5 KiB
TypeScript
/**
|
|
* Express authentication middleware.
|
|
* Validates JWT bearer tokens and attaches the decoded payload to the request.
|
|
* Provides role-based access control via higher-order middleware factories.
|
|
*/
|
|
import { Request, Response, NextFunction } from 'express';
|
|
import { JwtPayload } from '../types';
|
|
/** Express request extended with the authenticated user's JWT payload. */
|
|
export interface AuthRequest extends Request {
|
|
user?: JwtPayload;
|
|
}
|
|
/**
|
|
* Verifies the Authorization bearer token and attaches the decoded user to the request.
|
|
* @param req Express request (extended as AuthRequest on success)
|
|
* @param res Express response; sends 401 when the token is missing, invalid, or expired
|
|
* @param next Calls next() when authentication succeeds
|
|
*/
|
|
export declare function authMiddleware(req: AuthRequest, res: Response, next: NextFunction): Promise<void>;
|
|
/**
|
|
* Returns middleware that restricts access to requests whose user role is in the allowed list.
|
|
* Must run after authMiddleware so req.user is populated.
|
|
* @param roles One or more role names that are permitted (e.g. 'admin')
|
|
* @returns Express middleware that responds 401 without a user or 403 when the role is not allowed
|
|
*/
|
|
export declare function requireRoles(...roles: string[]): (req: AuthRequest, res: Response, next: NextFunction) => void;
|
|
/** Admin or moderator — support desk and similar staff tools. */
|
|
export declare function requireStaff(): (req: AuthRequest, res: Response, next: NextFunction) => void;
|
|
//# sourceMappingURL=auth.d.ts.map
|