How to convert Rule to Action

I’ve read that Rules will be soon deprecated and should be replaced with Actions.

I’ve a very simple rule that I don’t know how to convert.

This is the rule:

function (user, context, callback) {
  context.accessToken['http://localhost:3000/whatsapp'] = user.name;
  callback(null, user, context);
}

Is this the correct equivalent Action?

exports.onExecutePostLogin = async (event, api) => {
  event.context.accessToken['http://localhost:3000/whatsapp'] = event.user.name;
};

Hello @giovannilaperna welcome back!

Your Action should look like the following:

exports.onExecutePostLogin = async (event, api) => {
    api.accessToken.setCustomClaim('http://localhost:3000/whatsapp', event.user.name);
}

Hope this helps!

For some reason that didn’t work.
I had to set a public claim on my domain and use it also on localhost.

exports.onExecutePostLogin = async (event, api) => {

  api.accessToken.setCustomClaim('https://MY-DOMAIN/whatsapp', event.user.name);
  api.accessToken.setCustomClaim('https://MY-DOMAIN/loginsCount', event.stats.logins_count);
};
1 Like

Thanks for following up!

That’s interesting :thinking: Regardless, goo to know you got it working :smile: