feat(auth): enhance login and verification processes with detailed debug logging

- Added comprehensive debug logging to the login strategy and verification endpoint to track authentication flow and errors.
- Improved title determination logic for login and signup success/failure messages based on authentication status.
- Implemented middleware for logging request details on the login route to aid in debugging.
This commit is contained in:
chamikaJ
2025-06-02 13:07:50 +05:30
parent 5e4d78c6f5
commit 24fa837a39
3 changed files with 68 additions and 10 deletions

View File

@@ -17,7 +17,19 @@ const options = (key: string): passport.AuthenticateOptions => ({
successRedirect: `/secure/verify?strategy=${key}`
});
authRouter.post("/login", passport.authenticate("local-login", options("login")));
// Debug middleware for login
const loginDebugMiddleware = (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("=== LOGIN ROUTE HIT ===");
console.log("Request method:", req.method);
console.log("Request URL:", req.url);
console.log("Request body:", req.body);
console.log("Content-Type:", req.headers["content-type"]);
console.log("Session ID:", req.sessionID);
console.log("Is authenticated before:", req.isAuthenticated());
next();
};
authRouter.post("/login", loginDebugMiddleware, passport.authenticate("local-login", options("login")));
authRouter.post("/signup", signUpValidator, passwordValidator, passport.authenticate("local-signup", options("signup")));
authRouter.post("/signup/check", signUpValidator, passwordValidator, safeControllerFunction(AuthController.status_check));
authRouter.get("/verify", AuthController.verify);