Join Alexander Zanfir for an in-depth discussion in this video Create a login endpoint with Express, part of MEAN Stack and MongoDB: Development Techniques.
- [Voiceover] Let's open up our auth.js…and create a new login route in our Auth Controller.…Once again, we will use user.fineone…to try and find a user with the email…of the login request as we did with register.…So I'll just copy that.…And instead of existing user I'll call it user.…If we cannot find a user we could send the 401 error…letting them know the email or password was invalid.…
So once again, I'll make use of existing code…and copy this if condition.…Now, if the user was found we need…to check if they typed in the right password…by comparing the password we have in Mongo…and the password from the request.…If they match we will issue another token…with our create token function…we made earlier.…If they do not match we should send a 401…unauthorized error.…
I'll add a body to these conditions to make…it more readable.…And this actually should be if…the user is not found.…So let's fix that and give it a try.…So let's rerun Node and then let's try…it in our Angular app.…So make sure you fill in an email address…
- Installing and setting up your MEAN toolset
- Making an Angular post form
- Sending posts
- Displaying messages
- Creating a registration form
- Saving users
- Associating users with posts
- Authenticating users at login
Skill Level Intermediate
2. Message Posting
3. Display Messages
Save a user with Mongo13m 26s
5. Logging In
Next steps2m 5s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.