Auth0 Home Blog Docs

Running Rule Only Once at Sign Up

rules

#1

Hello,

I’m trying to call my backend API once to create a user when they have signed up. I created a rule that checks for loginCount === 1 as advised. The problem is, when using the React sample here the rule always gets called twice. In the logs, I do indeed see “Success Signup” followed by “Success Login”. In both cases, loginCount is 1 and the context is identical.

Needless to say, my servers throws an error at the second call. Any ideas how to prevent the second one from calling my server? In fact, why isn’t loginCount equal to 0 on “Success Signup”?

Thank you,
Sammy


#2

Hello @picosam The user is actually logged in when they sign up, which is why you are seeing loginCount === 1. I would suggest adding your own attribute to app_metadata to act as a flag. Your rule checks and sets the flag attribute:

{ 'app_metadata': {
  'my_flag_attribute': false
  }
}

Your rule will trigger when my_flag_attribute === false, do whatever processing it needs to do, then set my_flag_attribute === true.