Node.js Rules

Sample Project

Download this sample project configured with your Auth0 API Keys.

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

Create a Rule

To create a rule, go to the New Rule page. You can create a rule from scratch by selecting an empty rule, or you may use one of the existing templates. These templates are written by Auth0 to cover common scenarios and use cases.

For this example, select the Add country to the user profile rule.

Empty rule

This rule extracts the country_name from the context and adds it to the user profile as a new country attribute.

Add country rule

This is just the beginning, as you can edit the rule to meet your business needs. Once complete, click Save. The rule will execute any time a user logs in, and the country will be added to the user's profile.

Test the Rule Result

The following sample is based on the 01-Login source code. Add the following to the views/user.jade template to display the new country field:

extends layout

block content
  img(src="#{user.picture}")
  h2 Welcome #{user.nickname}!
  br
  p Country (Provided by Rule): <b>#{user._json.country}</b>
  br
  a(href='/logout') Logout
Previous Tutorial
5. Linking Accounts
Next Tutorial
7. Authorization
Use Auth0 for FREECreate free Account