Improve user session management and authentication for enhanced security

Integrates Passport.js sessions and updates authentication middleware logic in `auth.ts` and `routes.ts`.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: c5f0c281-8dd8-4846-b452-4a07bcd21062
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/d1d8abd3-0b74-4353-84ac-e56e863e16e5.jpg
This commit is contained in:
ghaddaditw
2025-06-08 08:17:35 +00:00
parent 11a5640243
commit 352be38902
2 changed files with 19 additions and 5 deletions
+3 -5
View File
@@ -6,18 +6,16 @@ export interface AuthenticatedRequest extends Request {
}
export const authMiddleware = async (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
if (!req.user) {
if (!req.isAuthenticated || !req.isAuthenticated()) {
return res.status(401).json({ error: 'Authentication required' });
}
try {
// Refresh user data from database
const user = await storage.getUser(req.user.id);
if (!user) {
// User is already available from Passport session
if (!req.user) {
return res.status(401).json({ error: 'User not found' });
}
req.user = user;
next();
} catch (error) {
console.error('Auth middleware error:', error);