Auth0 Home Blog Docs

Make a POST to API server using accessToken, after a user has registered


#1

I want to create a resource for the user when they first register. In order to do that I need the access token, of the newly created and logged in user.

I tried using Rules, but the accessToken is equal to an empty object after logging in for some reason.

function (user, context, callback) {
  console.log(user);
  console.log(context);
  
  if (context.stats.loginsCount === 1) {
    console.log("Creating example resource");
    
    const options = {
      method: 'POST',
      uri: "http://",
      headers: {
        "Authorization": "Bearer " + context.accessToken
      }
    };
    request(options, function(err, res) {
      console.log(res.body);
    });   
  }

  callback(null, user, context);
}

How do I send a POST after the user has logged in?