Files
microdao-daarion/backend/middleware/auth.middleware.ts
Apple 3de3c8cb36 feat: Add presence heartbeat for Matrix online status
- matrix-gateway: POST /internal/matrix/presence/online endpoint
- usePresenceHeartbeat hook with activity tracking
- Auto away after 5 min inactivity
- Offline on page close/visibility change
- Integrated in MatrixChatRoom component
2025-11-27 00:19:40 -08:00

40 lines
987 B
TypeScript

/**
* Auth Middleware
* Validates Bearer token
* MVP: Simple validation, replace with proper JWT validation later
*/
import type { Request, Response, NextFunction } from 'express';
export function authMiddleware(req: Request, res: Response, next: NextFunction): void {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
res.status(401).json({
error: 'UNAUTHORIZED',
message: 'Missing or invalid Authorization header',
});
return;
}
const token = authHeader.substring(7);
// MVP: Simple validation (just check token exists)
// TODO: Validate JWT token properly
if (!token) {
res.status(401).json({
error: 'UNAUTHORIZED',
message: 'Invalid token',
});
return;
}
// Attach user ID to request (MVP: extract from token)
// TODO: Decode JWT and extract userId
(req as any).userId = 'user_stub'; // Replace with actual user ID from token
next();
}