From the course: Advanced Express

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Setting up an authentication strategy for Passport

Setting up an authentication strategy for Passport

From the course: Advanced Express

Start my 1-month free trial

Setting up an authentication strategy for Passport

- [Narrator] Eventually we want to authenticate users against our MongoDB Database. For that, we already created a user model. Now we want to implement all flows and methods related to authentication. Let's open the auth.js. And as we know, passport gives us a set of different authentication strategies. To authenticate against the local database we need the local strategy. It's not bundled with passport. So we need to install the respective model. For that I'll run npm install, dash dash save, passport dash local. And now in auth.js I can add const, local strategy, equals require passport local, dot strategy. Next we have to add the strategy to passport. And for that we have a similar mechanism as express middle verse. So I add passport dot use. And here we'll now pass in the new local strategy. And by default this strategy will look for username and password in the body. But we want to use the email address here. So we have to set a configuration option for that. And to do that, add…

Contents