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
From the course: Advanced Express
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding cookies and sessions3m 54s
-
(Locked)
Adding cookies and sessions to Express5m
-
(Locked)
Inspecting the session object2m 18s
-
Introduction to Passport1m 39s
-
(Locked)
Adding Passport to Express3m 55s
-
(Locked)
Setting up an authentication strategy for Passport5m 18s
-
(Locked)
Serializing and deserializing users3m 25s
-
(Locked)
Creating a login form with Passport5m 14s
-
(Locked)
Providing a logout link2m 1s
-
(Locked)
Authentication vs. authorization1m 23s
-
(Locked)
Protecting routes3m 35s
-
-
-
-