Due to the future deprecation of Auth0 Rules, users are required to migrate their custom Rules to the latest Auth0 Actions.
This post will guide you through this migration process.
Auth0 Rule to migrate
Name: Add user information to access token
Script:
function (user, context, callback) {
// This rule adds the authenticated user's email address to the access token.
var namespace = 'https://mydomain.com/';
context.accessToken[namespace + 'email'] = user.email;
context.accessToken[namespace + 'email_verified'] = user.email_verified;
return callback(null, user, context);
}
Create Auth0 custom Action
-
Go to Actions → Flows → Login
-
Go to the “Custom” tab and click “Create Action”
-
Give the action a name
-
Here’s how the Action version of the old Auth0 Rule looks like:
exports.onExecutePostLogin = async (event, api) => { // This rule adds the authenticated user's email address to the access token. if (event.authorization) { const namespace = 'https://mydomain.com'; api.accessToken.setCustomClaim(`${namespace}/email`, event.user.email); api.accessToken.setCustomClaim(`${namespace}/email_verified`, event.user.email_verified); } };
-
You can click on the “Test” button before deploying
-
After you’ve the deployed the Action, you want to drag it into the Login flow
-
Make sure to click “Apply” in order to save the latest changes
-
Now you can disable the old Rule, since the new Action that we created has already been deployed
Additional resources
You can take a look at the docs for more comprehensive code examples on the new Auth0 Actions: