Can I set multiple custom claims to ID token in one action?

I encountered an issue when set multiple custom claims to ID token in the same action.

Here is my code:

exports.onExecutePostLogin = async (event, api) => {
  if (event.request && event.request.query && event.request.query.redirect_uri) {
    api.idToken.setCustomClaim('https://namespace-1.com/app_metadata', event.user.app_metadata);
    api.idToken.setCustomClaim('https://namespace-2.com/app_metadata', event.user.app_metadata);
    } 
  }
};

It works as expected for some users. The ID token contains two custom claims as defined above. However, some accounts will encounter infinite loop during the login process. It seems like they can’t be authenticated for some reasons.

Could anyone help me figure out why some accounts face login problem?

Hi @patrick.yu

I don’t think the infinite loop is with the code you showed.

Use the Real-time webtask logs extension and put console.log statements in all your actions to figure out what is going on.

John

1 Like