17 lines
372 B
TypeScript
17 lines
372 B
TypeScript
|
|
import { Request, Response, NextFunction } from 'express';
|
||
|
|
|
||
|
|
declare module 'express-session' {
|
||
|
|
interface SessionData {
|
||
|
|
userId?: string;
|
||
|
|
username?: string;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function requireAuth(req: Request, res: Response, next: NextFunction): void {
|
||
|
|
if (!req.session.userId) {
|
||
|
|
res.status(401).json({ error: 'Not authenticated' });
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
next();
|
||
|
|
}
|