简体   繁体   中英

Passport with Express 4

I'm following this guide for implementing Passport for signup:

https://scotch.io/tutorials/easy-node-authentication-setup-and-local

Everything works well, except that Passport does not redirect on successful signup. This is my code that I'm using to redirect on a successful signup:

//  POST        /signup
router.post('/signup', passport.authenticate('local-signup', {
    successRedirect : '/dashboard',
    failureRedirect : '/signup',
    failureFlash: true
}));

I have verified that the user is created in the database. failureRedirect works! It's just on successRedirect that the web page hangs like it's not being successfully redirected.

Is there an incompatibility issue with passport and Express 4 Router? I see all examples of Passport using app.post() instead of router.post().

Thanks!

It looks like you're deviating from the tutorial in that you're using successRedirect to go to a page called dashboard , not profile . Have you updated your app/routes.js file to reflect that ? app.get('/dashboard', isLoggedIn, function(req, res) {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM