Node.js User Profile

Sample Project

Download this sample project configured with your Auth0 API Keys.

System Requirements
  • NodeJS 4.3 or superior
  • Express 4.11
Show requirements

User Profile

Getting the user's profile information is very simple with Auth0. After the user has authenticated, a user object with the entire profile is attached to every express request.

Showing the User Profile

We can modify the /user endpoint to display the user object. Add the following to the views/user.jade template:

extends layout

block content
  img(src="#{user.picture}")
  h2 Welcome #{user.nickname}!
  br
  a(href='/logout') Logout
  h2 User Profile
  pre #{userProfile}

To have full access to the user profile on userProfile, we need to strigify the user object. Modify the / endpoint in views/user.js to include userProfile.

// views/user.js

// Get the user profile
router.get('/', ensureLoggedIn, function(req, res, next) {
  res.render('user', {
    user: req.user ,
    userProfile: JSON.stringify(req.user, null, '  ')
  });
});
Previous Tutorial
3. Custom Login
Use Auth0 for FREECreate free Account