Add data on Access Token - avoid Rules and Hooks

Hi Team,

I receive an email inform the Rules and Hooks will be discontinued.
I use Rule to add user data on ID_TOKEN. How I can add custom information on ID_TOKEN?

Sample fo Rule:

function (user, context, callback) {
// This rule adds user_metadata to idToken.
context.idToken[‘user.metadata’] = {
“custom_data_1”: user.user_metadata.custom_data_1
};
return callback(null, user, context);
}

Hi @douglas.freitas,

Welcome to the Auth0 Community!

Yes, that is correct! We recently made an announcement that Rules and Hooks is reaching the end of life:

Now, in this situation, what you will need to do is convert your existing Rule to a Post Login Action.

For your convenience, I have converted your Rule into a Post Action code snippet below:

exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
  if (event.authorization) {
    // Set claims
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata.custom_data_1);
  }
};

To assist you further, I’ve also gathered some helpful resources that you can refer to:

Please let me know if there is anything else I can do to help!

Thanks,
Rueben

1 Like

Thank you Rueben!

I will test with your sample and read more in references!

Best regards

1 Like

Hi @douglas.freitas,

Of course, you’re welcome!

Regards,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.