Redirect to onboarding flow after sign up (or first log in)?

@dan.woda Maybe not? :smiley:

Just fixed my rule to this:

function (user, context, callback) {
    var request = require("request");
    var count = context.stats && context.stats.loginsCount ? context.stats.loginsCount : 0;
  
    // Debug
    console.log(`${context.request.ip} signing in, lc=${count}`);
  
    // Add log in count to JWT
    context.accessToken['https://<namespace>/loginCount'] = count;
    
    // Exit fast if not first login
    if (count > 0) {
      return callback(null, user, context);
    }
  
    /**
     * Add default role to new users on first log in
     **/
    var headers = {
        'Authorization': 'Bearer ' + auth0.accessToken,
    };
  
    const data = {
        "roles": [
            "role_id"
        ]
    };

    request.post({
        url: `https://${auth0.domain}/api/v2/users/${user.user_id}/roles`,
        headers: headers,
        json: data
    }, (err, response, body) => {
        return callback(new Error("Can not update users with role"));
    });

    callback(null, user, context);
}

I also installed real time logs for the debug line near the top:

12:04:55 PM: new webtask request
12:04:55 PM: XXX.XXX.XXX.XXX signing in, lc=1
12:04:55 PM: finished webtask request

I used a brand new user. I donā€™t have verification required before log in ā€“ sign up logs the user in.

Regardless, it was not 0 at first log in; it was 1. Iā€™ll need to figure out which one it is and when (maybe itā€™s 0 when email verification is required? Iā€™ll check.)

EDIT: Nevermind. I forgot that requiring email verification is a rules-based task with auth0. I donā€™t think that will change much.

I just tested it and am also getting 1 on a new signup first login. I am trying to think of the edge case where it would be zero/undefinedā€¦but yes, it looks like it is 1 on a typical first login.

Hmm okay. Well, if it is a really infrequent case where itā€™s undefined then setting to 1 if it is undefined vs setting it to 0 should be completely fine, right?

That makes sense to me.

1 Like

Thanks for all your help! Really appreciate it.

1 Like

No problem! Thanks for jumping in on other topics and being an active user. We appreciate all the help we can get. Cheers.

1 Like

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