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 team! :waving_hand:

Since this topic touches Auth0 Actions, quick heads-up that we’re hosting an Ask Me Anything dedicated to Actions with Gaston Danilo Asis Sanchez, Senior Technical Product Manager. We’ll cover practical usage, new capabilities like Transaction Metadata and Actions Types, plus a peek at what’s next. :sparkles:

  • Submit questions now through Aug 26 :writing_hand:
  • Get detailed written answers live on Aug 27, 9–11 AM PT :speech_balloon:

Earn community points + a badge :trophy:. If you’re exploring how Actions can streamline your auth flows, this is a great time to get direct guidance from the team.
Join the AMA & drop your questions here: August 27 Auth0 Community Ask Me Anything: Actions

Dawid