In Custome Action not able to import axios

Dear Team,
I am relatively new and trying to enrich my user profile using onExecutePostLogin. Here is simple snippet

exports.onExecutePostLogin = async (event, api) => {
  
  const axios = require('axios');

  const namespace = 'https://dhanman.com';

   let access_token = await axios.post(`https://${event.secrets.auth0_domain}/oauth/token`, {
    "client_id": event.secrets.client_id,
    "client_secret": event.secrets.client_secret,
    "audience": "http://PostLoginApi",
    "grant_type": "client_credentials"
  });
  
  let users_response = await axios.get(`<mysite>/v1/users/${event.user.email}`, {
    headers: {
      'Authorization': `Bearer ${access_token.data.access_token}`
    }
  });

  if(users_response.data){
    api.accessToken.setCustomClaim(`${namespace}/dhanman_id`, users_response.data.id);
    api.idToken.setCustomClaim(`${namespace}/dhanman_id`, users_response.data.id);
  }
};

The error I am facing is below

{
  "error": "access_denied",
  "error_description": "Cannot find module 'axios'\nRequire stack:\n- /data/io/node18-actions/93635820-6a85-4e93-916c-f21eb9a1887a/webtask.js"
}

and when I use import axios from “axios”;
It gives error that import is not allowed outside module.

Any help is much appreciated.

Thank you
B2A

I found the fix, as in the new version we need to specify the dependency.
However, now I am facing a new issue while accessing the token.
The error is

{
  "error": "access_denied",
  "error_description": "getaddrinfo ENOTFOUND undefined"
}

THe error is coming for the section

let access_token = await axios.post(`https://${event.secrets.domain}/oauth/token`, {
    "client_id": event.secrets.client_id,
    "client_secret": event.secrets.client_secret,
    "audience": "http://PostLoginApi",
    "grant_type": "client_credentials"
  });

I would like to know what is the best way to access the Bearer token

Kind Regards
B2A

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!