working on new login sign up flow

This commit is contained in:
jackiettran
2025-07-29 23:48:09 -04:00
parent 6cba15d36a
commit 72d79596ce
10 changed files with 763 additions and 29 deletions

View File

@@ -11,7 +11,14 @@ const authenticateToken = async (req, res, next) => {
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
const user = await User.findByPk(decoded.userId);
// Handle both 'userId' and 'id' for backward compatibility
const userId = decoded.userId || decoded.id;
if (!userId) {
return res.status(401).json({ error: 'Invalid token format' });
}
const user = await User.findByPk(userId);
if (!user) {
return res.status(401).json({ error: 'User not found' });
@@ -20,6 +27,7 @@ const authenticateToken = async (req, res, next) => {
req.user = user;
next();
} catch (error) {
console.error('Auth middleware error:', error);
return res.status(403).json({ error: 'Invalid or expired token' });
}
};