Apollo Client in Auth0 Actions

Hi there,

i have a GraphQL API for my Backend. Now i want to create some sample data when the user logged in for the first time. I tried the Auth0 Actions PostSignup because i thought this is the best way. Unfortunately i cant get the Apollo Client to work, thats my current code:

exports.onExecutePostUserRegistration = async (event, api) => {
  var fetch = require('cross-fetch');
  var _client = require('@apollo/client');
  var gql = require('@apollo/client');
  
  const client = new _client.ApolloClient({
    uri: new _client.HttpLink({ uri: 'https://api.***.de', fetch }),
    cache: new _client.InMemoryCache(),
  });

  client 
  .query({
    query: gql`
      query Todos {
        getTodos {
          createdAt
          description
          id
          isCompleted
          title
          userID
        }
      }
    `,
  })
  .then((result) => console.log(result));
};`Preformatted text`

I get this error: "\n"fetch" has not been found globally and no fetcher has been configured.

Do you have any idea whats wrong here ? Or do you even know a way i could implement this maybe in my own project ? I use NextJS.

Thanks!

Hi @chrisar,

Welcome to the Auth0 Community!

This error happens when you are trying to use a module that was not installed in your Action’s Dependencies.

Let me also add that you can only install modules found here.

For this behavior, I recommend using a Post-Login Action instead of a Post-User Registration Action and checking if the user’s logins_count === 1.
For example:

exports.onExecutePostLogin = async (event, api) => {
  if(event.stats.logins_count === 1){
    //YOUR CODE HERE
  }
};

Please reach out if you have any additional questions.

Thanks,
Rueben

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.