games_app/backend/dist-test-faq/middleware/auth.d.ts

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.
*/
export declare function authMiddleware(req: AuthRequest, res: Response, next: NextFunction): Promise<void>;
/**
* Restricts access to users whose roles intersect the allowed list.
* `super_admin` satisfies routes that require `admin`.
* Admin routes also enforce mandatory 2FA when configured.
*/
export declare function requireRoles(...roles: string[]): (req: AuthRequest, res: Response, next: NextFunction) => Promise<void>;
/** Requires every listed permission on the JWT payload. */
export declare function requirePermissions(...perms: string[]): (req: AuthRequest, res: Response, next: NextFunction) => Promise<void>;
/** Admin or super_admin. */
export declare function requireAdmin(): (req: AuthRequest, res: Response, next: NextFunction) => Promise<void>;
/** Admin, moderator, or super_admin — support desk and similar staff tools. */
export declare function requireStaff(): (req: AuthRequest, res: Response, next: NextFunction) => Promise<void>;
//# sourceMappingURL=auth.d.ts.map