Is it possible to use async/await in rules or some similar construct?

Hi.

I have created a rule that assigns roles based on users ad groups connected in azure ad.
The rule first delete all roles for the user and then assigns new roles based on the mapped ad group data.
I use “request” to call the auth0 management api for the delete and assignment.
My problem is that the calls executes async so somtimes the delete comes after the assignment.
Is it possible to get it synchronously?
If so, can you please show an example.

Best regards Roland

Hi @roland.eriksson,

Yes, you shouldn’t have a problem with that.

I use axios because the request library is deprecated. Here is an example:

function (user, context, callback) {
  const axios = require('axios');
  
  const getEcho = async () => {
    try {
      const resultA = await axios.get('https://postman-echo.com/get?foo1=bar1');
      console.log(resultA.data);
      const resultB = await axios.get(`https://postman-echo.com/get?foo2=${resultA.data.args.foo1}`);
      console.log(resultB.data);
    } catch (error) {
      console.error(error);
    }
  };

  getEcho();
  return callback(null, user, context);
}

Thank you very much. Works as a charm.

1 Like

No problem. Let us know if you have any other questions!