I wanted to make a login system with Passport. Everything went well until I tried to login with an username and a password. On invalid/wrong credentials it warns me with a flash message but on valid credentials it justs spins there for an eternity and does literally nothing.
Here's the code
const express = require("express");
const router = express.Router();
const User = require("../models/user");
const catchAsync = require("../utils/catchAsync");
const passport = require("passport");
router.get("/register", (req, res) => {
res.render("users/register");
});
router.post("/register", catchAsync(async (req, res) => {
try {
const {email, username, password} = req.body;
const user = new User({email, username});
await User.register(user, password);
req.flash("success", "Welcome to Yelp Camp!");
res.redirect("/campgrounds");
} catch (e) {
req.flash("error", e.message);
res.redirect("/register");
}
}));
router.get("/login", (req, res) => {
res.render("users/login");
});
router.post("/login", passport.authenticate("local", {failureFlash: true, failureRedirect: "/login"}), (req, res) => {
req.flash("success", "WELCOME BACK!");
res.redirect("/campgrounds");
})
module.exports = router;
Even tried with successRedirect from the docs but the results it's still the same. Thanks in advance!
question from:
https://stackoverflow.com/questions/65914774/passport-authenticatelocal-doesnt-redirect-to-some-page 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…