I’m migrating from Rules to Actions and when and the following doesn’t work for me -
var getDb = require('mongo-getdb');
exports.onExecutePostLogin = async (event, api) => {
var namespace = 'https://mydomain.com/';
getDb('myconnectionstring', function (db) {
api.idToken.setCustomClaim(namespace + 'appId',"12345678");
}
}
when I put the setCustomClaim outside of the getDB callback I do get the claim in the token, but when the setCustomClaim is inside there is no claim in the token.
any ideas?
Thanks
Actions are quite flexible but don’t work 1:1 as the Rules feature.
In case you would want to add custom claims if the user logs in in the context of your legacy database, or to a specific app (login context data) then you can use the event object and the properties associated: event.connection and event.client, respectively. More on that here.
Later, based on that context data, you can make further login decisions / add custom claims with the apiobject.
For a generic detailed design, please see this github repo. In case, more guidance is needed, Auth0 Professional Services 39 can definitely assist in designing/implementing an architecture, aligning to security best practices.