Rules adds email to custom claims, but not working with actions

Here’s my rule -

function addEmailToAccessToken(user, context, callback) {
  // This rule adds the authenticated user's email address to the access token.

  var namespace = 'https://logkeeper.com/';

  context.accessToken[namespace + 'email'] = user.email;
  return callback(null, user, context);
}

Here’s my action:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://logkeeper.com/'

  api.accessToken.setCustomClaim(namespace + 'email', event.user.email)
};

The action doesn’t work, but the rule works fine.

What’s going on?

Hey @KLP ,

I tried to reproduce your issue, and did the following:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
    // Set a claim 
    api.accessToken.setCustomClaim(`${namespace}/preferred_contact`, event.user.email);
  };


And I got the token with the custom claim and value:
"https://myapp.example.com/preferred_contact": "marcelina.bxxx@xxx.com",

Can you please try in a similar way? Thanks!

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