text changes and remove infra folder
This commit is contained in:
@@ -28,8 +28,7 @@ const router = express.Router();
|
||||
const googleClient = new OAuth2Client(
|
||||
process.env.GOOGLE_CLIENT_ID,
|
||||
process.env.GOOGLE_CLIENT_SECRET,
|
||||
process.env.GOOGLE_REDIRECT_URI ||
|
||||
"http://localhost:3000/auth/google/callback"
|
||||
process.env.GOOGLE_REDIRECT_URI,
|
||||
);
|
||||
|
||||
// Get CSRF token endpoint
|
||||
@@ -120,7 +119,7 @@ router.post(
|
||||
try {
|
||||
await emailServices.auth.sendVerificationEmail(
|
||||
user,
|
||||
user.verificationToken
|
||||
user.verificationToken,
|
||||
);
|
||||
verificationEmailSent = true;
|
||||
} catch (emailError) {
|
||||
@@ -137,13 +136,13 @@ router.post(
|
||||
const token = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion },
|
||||
process.env.JWT_ACCESS_SECRET,
|
||||
{ expiresIn: "15m" } // Short-lived access token
|
||||
{ expiresIn: "15m" }, // Short-lived access token
|
||||
);
|
||||
|
||||
const refreshToken = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion, type: "refresh" },
|
||||
process.env.JWT_REFRESH_SECRET,
|
||||
{ expiresIn: "7d" }
|
||||
{ expiresIn: "7d" },
|
||||
);
|
||||
|
||||
// Set tokens as httpOnly cookies
|
||||
@@ -188,7 +187,7 @@ router.post(
|
||||
});
|
||||
res.status(500).json({ error: "Registration failed. Please try again." });
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.post(
|
||||
@@ -220,7 +219,8 @@ router.post(
|
||||
// Check if user is banned
|
||||
if (user.isBanned) {
|
||||
return res.status(403).json({
|
||||
error: "Your account has been suspended. Please contact support for more information.",
|
||||
error:
|
||||
"Your account has been suspended. Please contact support for more information.",
|
||||
code: "USER_BANNED",
|
||||
});
|
||||
}
|
||||
@@ -242,13 +242,13 @@ router.post(
|
||||
const token = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion },
|
||||
process.env.JWT_ACCESS_SECRET,
|
||||
{ expiresIn: "15m" } // Short-lived access token
|
||||
{ expiresIn: "15m" }, // Short-lived access token
|
||||
);
|
||||
|
||||
const refreshToken = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion, type: "refresh" },
|
||||
process.env.JWT_REFRESH_SECRET,
|
||||
{ expiresIn: "7d" }
|
||||
{ expiresIn: "7d" },
|
||||
);
|
||||
|
||||
// Set tokens as httpOnly cookies
|
||||
@@ -292,7 +292,7 @@ router.post(
|
||||
});
|
||||
res.status(500).json({ error: "Login failed. Please try again." });
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.post(
|
||||
@@ -314,9 +314,7 @@ router.post(
|
||||
// Exchange authorization code for tokens
|
||||
const { tokens } = await googleClient.getToken({
|
||||
code,
|
||||
redirect_uri:
|
||||
process.env.GOOGLE_REDIRECT_URI ||
|
||||
"http://localhost:3000/auth/google/callback",
|
||||
redirect_uri: process.env.GOOGLE_REDIRECT_URI,
|
||||
});
|
||||
|
||||
// Verify the ID token from the token response
|
||||
@@ -413,7 +411,8 @@ router.post(
|
||||
// Check if user is banned
|
||||
if (user.isBanned) {
|
||||
return res.status(403).json({
|
||||
error: "Your account has been suspended. Please contact support for more information.",
|
||||
error:
|
||||
"Your account has been suspended. Please contact support for more information.",
|
||||
code: "USER_BANNED",
|
||||
});
|
||||
}
|
||||
@@ -422,13 +421,13 @@ router.post(
|
||||
const token = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion },
|
||||
process.env.JWT_ACCESS_SECRET,
|
||||
{ expiresIn: "15m" }
|
||||
{ expiresIn: "15m" },
|
||||
);
|
||||
|
||||
const refreshToken = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion, type: "refresh" },
|
||||
process.env.JWT_REFRESH_SECRET,
|
||||
{ expiresIn: "7d" }
|
||||
{ expiresIn: "7d" },
|
||||
);
|
||||
|
||||
// Set tokens as httpOnly cookies
|
||||
@@ -488,7 +487,7 @@ router.post(
|
||||
.status(500)
|
||||
.json({ error: "Google authentication failed. Please try again." });
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Email verification endpoint
|
||||
@@ -605,7 +604,7 @@ router.post(
|
||||
error: "Email verification failed. Please try again.",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Resend verification email endpoint
|
||||
@@ -650,7 +649,7 @@ router.post(
|
||||
try {
|
||||
await emailServices.auth.sendVerificationEmail(
|
||||
user,
|
||||
user.verificationToken
|
||||
user.verificationToken,
|
||||
);
|
||||
} catch (emailError) {
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
@@ -691,7 +690,7 @@ router.post(
|
||||
error: "Failed to resend verification email. Please try again.",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Refresh token endpoint
|
||||
@@ -727,7 +726,8 @@ router.post("/refresh", async (req, res) => {
|
||||
// Check if user is banned (defense-in-depth, jwtVersion should already catch this)
|
||||
if (user.isBanned) {
|
||||
return res.status(403).json({
|
||||
error: "Your account has been suspended. Please contact support for more information.",
|
||||
error:
|
||||
"Your account has been suspended. Please contact support for more information.",
|
||||
code: "USER_BANNED",
|
||||
});
|
||||
}
|
||||
@@ -736,7 +736,7 @@ router.post("/refresh", async (req, res) => {
|
||||
const newAccessToken = jwt.sign(
|
||||
{ id: user.id, jwtVersion: user.jwtVersion },
|
||||
process.env.JWT_ACCESS_SECRET,
|
||||
{ expiresIn: "15m" }
|
||||
{ expiresIn: "15m" },
|
||||
);
|
||||
|
||||
// Set new access token cookie
|
||||
@@ -851,7 +851,7 @@ router.post(
|
||||
"Password reset requested for non-existent or OAuth user",
|
||||
{
|
||||
email: email,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -871,7 +871,7 @@ router.post(
|
||||
error: "Failed to process password reset request. Please try again.",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Verify reset token endpoint (optional - for frontend UX)
|
||||
@@ -925,7 +925,7 @@ router.post(
|
||||
error: "Failed to verify reset token. Please try again.",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Reset password endpoint
|
||||
@@ -1008,7 +1008,7 @@ router.post(
|
||||
error: "Failed to reset password. Please try again.",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user