# Why is the condition in this rule firing every time?

**URL:** <https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490>\
**Category:** Get Help\
**Tags:** rules\
**Created:** [July 13, 2017, 2:07am UTC](https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490 "2017-07-13T02:07:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Buckley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dylan_buckley/32/2430_2.png) [@Dylan\_Buckley](https://community.auth0.com/u/Dylan_Buckley)\
**Post date:** [July 13, 2017, 2:07am UTC](https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490/1 "2017-07-13T02:07:49Z")

</div>

I only want this to fire if there is no value for `user.app_metadata.paid_account` but it is firing and updating every time a user logs in even if they already have this value!

This previously worked fine.

```
function (user, context, callback) {
  user.app_metadata = user.app_metadata || {};

  if (!user.app_metadata.paid_account) {
    user.app_metadata.paid_account = false;
    var date = new Date();
    user.app_metadata.trial_end_date = date.setDate(date.getDate() + 7);
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
      .then(function(){
        callback(null, user, context);
      })
      .catch(function(err){
        callback(err);
      });
  }
}

```

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [July 13, 2017, 3:09am UTC](https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490/2 "2017-07-13T03:09:58Z")

</div>

@dylan can you clarify the following:

1. How have you verified that this is firing? Have you used the [Realtime webtask logs extension](https://auth0.com/docs/extensions/realtime-webtask-logs), with console.log() outputs within the code block?
2. Are you calling the callback anywhere outside of the `if` statement?
3. Do you have any [Hooks](https://auth0.com/docs/hooks) that may be populating the `user.app_metadata.paid_account`?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [July 13, 2017, 3:30pm UTC](https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490/3 "2017-07-13T15:30:52Z")

</div>

You’re applying a logical NOT operator to the expression `user.app_metadata.paid_account`. The expression will be falsy when the property is undefined, but also for: null, false, -0, +0, NaN, “”.

Since you’re then setting the property to `false`, next iterations will still trigger the condition because the falsy value is inverted to a truthy value by the logical NOT operator. **If you only want to execute the body of the condition when the property is not yet defined you should instead use** :

```
if (user.app_metadata.paid_account === undefined) {
    // ....
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:55am UTC](https://community.auth0.com/t/why-is-the-condition-in-this-rule-firing-every-time/7490/4 "2018-03-02T05:55:20Z")

</div>


