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
This commit is contained in:
39
backend/middleware/auth.middleware.ts
Normal file
39
backend/middleware/auth.middleware.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user