Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Adding User Login 1:16
- Tracking Visits With Sessions and Cookies 2:22
- Working with Sessions in Express 3:28
- Review: Sessions, Cookies and Express 5 questions
- Adding Log In Routes 1:39
- Creating a Login Form With Pug (Jade) 2:48
- Authenticating the Username and Password 7:28
- Creating the Profile Route and Page 3:53
- Review: Login Routes 5 questions
Well done!
You have completed User Authentication With Express and Mongo!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Create the user profile page using the Pug templating language.Add programming logic to password protect the profile page for unauthorized users, or show user information for the currently logged in user.
Profile template code
profile.pug
extends layout
block content
.main.container.clearfix
.row
.col-md-8.col-md-offset-2
h1.display-4
img.avatar.img-circle.hidden-xs-down(src='/images/avatar.png', alt='avatar')
| #{name}
h2.favorite-book Favorite Book
| #{favorite}
GET /profile route
// GET /profile
router.get('/profile', function(req, res, next) {
if (! req.session.userId ) {
var err = new Error("You are not authorized to view this page.");
err.status = 403;
return next(err);
}
User.findById(req.session.userId)
.exec(function (error, user) {
if (error) {
return next(error);
} else {
return res.render('profile', { title: 'Profile', name: user.name, favorite: user.favoriteBook });
}
});
});
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Jason Pallone
11,340 Points2 Answers
-
Marcos Cabrini Riani dos Reis
12,253 Points1 Answer
-
benjaminfarnham
8,055 Points1 Answer
-
Serdar Halac
15,259 Points0 Answers
-
Brian Patterson
19,588 Points1 Answer
-
Tennyson Horn
14,660 Points0 Answers
-
Andrew Gursky
12,576 Points1 Answer
-
Paul Scarpa
1,329 Points0 Answers
-
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,625 PointsChange favorite book on profile page
3 Answers
-
Alex Bussey
20,846 Points0 Answers
-
Lucas Santos
19,315 PointsCan you please explain your use of the .exec method
Posted by Lucas SantosLucas Santos
19,315 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up