feat(auth): Introduce 5-day grace period for email verification before lockout
This commit is contained in:
+11
-3
@@ -30,9 +30,17 @@ const verifyToken = (req, res, next) => {
|
||||
|
||||
const requireEmailVerification = async (req, res, next) => {
|
||||
try {
|
||||
const userCheck = await pgPool.query('SELECT is_email_verified FROM users WHERE id = $1', [req.user.id]);
|
||||
if (userCheck.rows.length === 0 || !userCheck.rows[0].is_email_verified) {
|
||||
return res.status(403).json({ error: 'Email verification required' });
|
||||
const userCheck = await pgPool.query('SELECT is_email_verified, created_at FROM users WHERE id = $1', [req.user.id]);
|
||||
if (userCheck.rows.length === 0) return res.status(403).json({ error: 'User not found' });
|
||||
|
||||
const user = userCheck.rows[0];
|
||||
if (!user.is_email_verified) {
|
||||
const createdAt = new Date(user.created_at);
|
||||
const now = new Date();
|
||||
const daysSinceCreation = (now.getTime() - createdAt.getTime()) / (1000 * 60 * 60 * 24);
|
||||
if (daysSinceCreation > 5) {
|
||||
return res.status(403).json({ error: 'Email verification grace period expired (5 days)' });
|
||||
}
|
||||
}
|
||||
next();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user