Another (hopefully simple) passport question (passport.authenticate())

I'm following a great passport guide by a guy called zach gollwitzer - would really recommend: https://www.youtube.com/watch?v=F-sFp_AvHc8 He talks about using the
passport.authenticate('local', {failureRedirect: '/login-failure', successRedirect: 'login-success'})
passport.authenticate('local', {failureRedirect: '/login-failure', successRedirect: 'login-success'})
as middleware in my route: So route.post('/login', passport.authenticate(...), controller.login()) He says that I don't need controller.login() because authenticate provides success and failure redirects. But I'm using a REST backend, so I'm not redirecting anywhere. The passport docs say that the function will produce an HTTP 401 Unauthorized response... and the request-response cycle will end. when authentication fails. So I'm guessing I can just deal with the successful logic in controller.login(), and that authenticate will just call next if successful?
freeCodeCamp.org
YouTube
User Authentication in Web Apps (Passport.js, Node, Express)
In this full course for beginners, you will learn how to implement user authentication from scratch in your web apps. You will learn how to use Passport.js in a Node / Express app. šŸ’» Starter Code šŸ”— https://github.com/zachgoll/express-session-authentication-starter šŸ”— https://github.com/zachgoll/express-jwt-authentication-starter āœļø Course creat...
1 Reply
nickymicky
nickymickyā€¢2y ago
I've done 2 projects using passport.js and this is the first time seeing the controller.login() middleware. My apps work fine without it, so I don't think it is needed.
Want results from more Discord servers?
Add your server