Redirect a user to url via Auth0 Rules

I am currently using multiple rules to evaluate different user stages. This is the first rule that gets executed. However the rule redirection to the custom URL is not working. Also new users are getting redirected to the application and not the custom URL. The URL was already added to the list of Allowed Callback URLs.

function (user, context, callback) {

  console.log('RULE: Running Set roles of new users');
  console.log('[before] user.app_metadata: ' + user.app_metadata);
  
  user.app_metadata = user.app_metadata || {};

  if (user.app_metadata.signedUp) {
    console.log('This is not the first sign in.');
    return callback(null, user, context);
  }

    user.app_metadata.signedUp = true;
    user.app_metadata.roles = ["Not Approved user"];
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
      .then(function () {
        console.log('[after] user.app_metadata: ' + user.app_metadata);
        context.redirect = {          
          url: "https://example.com"
        };
      console.log('Redirect to custom success page');
      return callback(null, user, context);
      })
      .catch(function (err) {
        callback(err);
      });
}

However this line gets fired and the output is visible in the console. console.log('Redirect to custom success page');

Why is the redirection not working?

@konrad.sopala

Hey there!

Let me check it and get back to you with my thoughts!

So first things first:

Can you check whether the first bullet point is not a problem here? Thank you!

@konrad.sopala If the authentication is successful, the user gets redirected to the application.

If a user creates an account via Auth0 Lock they get automatically signed in. That’s their first sign in and and they should get redirected to a custom webpage on my server that says: “SignUp was successful”
I have a rules that takes care of this.

For more information please check the rules in my tenant because of the sensitivity of the data.

@konrad.sopala Any new ideas on this?

Hey there!

Terribly sorry for the delay in response! We’re doing our best in providing you with best developer support experience out there but sometimes the number of incoming questions is too big.

Can you let me know if you’re still struggling with that? I checked the code snippet and compared it with our docs and when it comes to this rule that you shared the redirect should happen and is triggered the right way. Are you sure that there isn’t another rule that can be conflicting with this one?

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