Alternative to using rule to attach email to access tokens

Hello @jmdot welcome to the community!

Similar to a rule, you will just need to add email as a custom claim using an Action - A Post Login Action should work for this and look like the following:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com/';
  const email = event.user.email;

  if (email) {
    api.accessToken.setCustomClaim(`${namespace}email`, email);
  }
};

Since email is not a restricted claim you can also forego using a namespace:

exports.onExecutePostLogin = async (event, api) => {
  const email = event.user.email;

  if (email) {
    api.accessToken.setCustomClaim('email', email);
  }
};

1 Like