Skip to content

Commit

Permalink
Refactor login route to always render login page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kratospidey committed Feb 27, 2024
1 parent 3de8a4f commit 80f9889
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,7 @@ app.get("/", (req, res) => {
});

app.get("/login", (req, res) => {
// Check if the user's request contains a token cookie
const token = req.cookies.token;

if (token) {
try {
// Verify the token using the same secret key used to sign the JWT
const decoded = jwt.verify(token, SECRET_KEY);

// If the token is valid, redirect to /home
return res.redirect("/home");
} catch (err) {
// If the token is not valid, catch the error (it might be expired or invalid)
console.error("Error verifying token:", err);
}
}

// If there's no token or it's invalid, render the login page
// Always render the login page regardless of any existing tokens or user state
res.render("login");
});

Expand Down

0 comments on commit 80f9889

Please sign in to comment.