Actions with async metadata/custom claims

We’re using actions to add custom claims to the accessToken and the content of the claims are coming from either an API request or a MySQL query, but the problem is, I believe due to the async nature of the requests they’re not actually getting applied. I’ve got the following:

await runquery(event.user.user_metadata.i_account, async (acl_meta) => {

        console.log(acl_meta);

        if (acl_meta) {

            await api.accessToken.setCustomClaim(`https://metadata.client/acl`, acl_meta);

            return;

        }

    });

    var req = unirest('GET', 'https://jsonplaceholder.typicode.com/todos/1')

    .end(function (res) { 

        if (res.error) throw new Error(res.error); 

        console.log(res.raw_body);

        var json = JSON.parse(res.raw_body)

        api.accessToken.setCustomClaim("https://metadata.client/acls/",json);

        return;

    });

Where runquery is a callback function of a MySQL query, though doing the same in the callback from the MySQL query i.e.:


await connection.query('SELECT bitflag FROM acl_accounts WHERE i_account=' + i_accont, function (error, results, fields) {    
       //ADD CUSTOM CLAIMS HERE
});

Does not work either. I’ve tried with and without await, Anybody got any advice?

Regards,
Joe

1 Like

Hi Joe,
have solved your problem? I think I might get a similar issue.

Best regards,
Greg

1 Like

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!