Kevin Powell - CommunityKP-C
Kevin Powell - Community•3y ago•
1 reply
JWode

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'})

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?
YouTubefreeCodeCamp.org
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...
User Authentication in Web Apps (Passport.js, Node, Express)
Was this page helpful?