Redirect on signup to "Create Profile" Page

Hi,

I am trying to redirect users to a “Create Profile” page after their sign up. I have created a rule that checks the login count through following rule.

function (user, context, callback) {
  var count = context.stats && context.stats.loginsCount ? context.stats.loginsCount : 0;
  if (count === 1) {
    context.redirect = {
      url: "http://localhost:3000/capture-details"
    };
    return callback(null, user, context);
  }
  else {
        context.redirect = {
      url: "http://localhost:3000"
    };
    return callback(null, user, context);
   }
  
}

Now this does redirect properly, but after sign up the page keeps reloading for reasons I can’t think of.
Is there something wrong with the rule that I have created?

Hi @devajain,

Welcome to the Community!

I would guess that this redirect rule is being run again, which could cause some issues. Using a flag on the user’s app_metadata may be better than login count.

This doc may be helpful:

Hi Dan,

Thank you for your response.

function (user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  console.log(user.user_metadata.createdProfile);
  if (user.user_metadata.createdProfile === true) {
    context.redirect = {
      url: "http://localhost:3000"
    };
  }
  else {
        context.redirect = {
      url: "http://localhost:3000/capture-details"
    };
    
  }
  return callback(null, user, context);
  
}

So, I am updating the user_metadata with a field “createdProfile: true” and using this rule to redirect to another page if the profile on my database is already created and I am still facing the same issue. (page keeps reloading)

Is there something wrong with the rule?

It sounds like you are redirecting from this rule and never resuming the rules flow.

Context.redirect allows you to redirect mid-authentication, and expects you to redirect back after collecting whatever information, and resume the auth flow.

Are you redirecting and never resuming authentication?

Yes I wish to redirect and never resume authentication

The redirect that occurs after authentication is determined by the redirect_uri that is sent during the initial request (from your application).

Many of our customers choose to do a redirect within a rule, just like you are doing, to collect this type of information. The advantage of using a rule is the fact that your can require the information is received before granting access, making the process mandatory. All you have to do is resume authentication after the fact. The first doc I linked lays out how to resume authentication.

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