# Rule Not Updating my app\_metadata but in debug it works

**URL:** <https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009>\
**Category:** Get Help\
**Tags:** app\_metadata, rules, auth0\
**Created:** [March 24, 2021, 8:53pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009 "2021-03-24T20:53:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oflores2313](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oflores2313/32/28356_2.png) [@oflores2313](https://community.auth0.com/u/oflores2313)\
**Post date:** [March 24, 2021, 8:53pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/1 "2021-03-24T20:53:47Z")

</div>

I have a rule in place that calls an external public api and returns data if the email exists. based on that data i set :

user.app\_metadata.roles = userData;  
user.app\_metadata.companyId = userCompany;

when i debug it or i test it. It works and i see my data update. Now if I test it using the google auth, it does not work at at all. When i go to the user section in auth0 is does not show my updated app\_metadata… Any ideas?

TIA!

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [March 25, 2021, 1:08pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/2 "2021-03-25T13:08:11Z")

</div>

Hi @oflores2313

Install the real-time webtask logs extension and use console.log to view what is happening in the non-debug case.

John

---

<div class="post-metadata">

**Author:** ![oflores2313](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oflores2313/32/28356_2.png) [@oflores2313](https://community.auth0.com/u/oflores2313)\
**Post date:** [March 25, 2021, 2:20pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/3 "2021-03-25T14:20:11Z")

</div>

I did and my profile is set correctly there when i console log it.

This is my code. Am i doing something wrong here:

```
function setRolesToUser(user, context, callback) {
  // setting my meta data
  user.app_metadata = user.app_metadata || {};
  user.app_metadata.roles = user.app_metadata.roles || '';
  user.app_metadata.companyId = user.app_metadata.companyId || '';

  console.log('OSCAR USER PROFILE', user);
	
  var axios = require("axios").default;
  var options = {
  	method: 'GET',
    url: `http://e68c26fc1d1d.ngrok.io/users/find-user?email=${user.email}`,
    headers: {'content-type':'application/json'}
  };
  
  axios(options)
  .then( res => {
    console.log(res);
  	let userData;
    let userCompany;
    // checking if theres any returned data
    if(res.data.length === 0){
      userData = '';
      userCompany = '';
    }else {
      console.log('res:', res.data);
      // if data is returned from the API, then set the role and the companyId
      userData = res.data[0].role.role_name;
      userCompany = res.data[0].company_id;
    }
    user.app_metadata.roles = userData;
    user.app_metadata.companyId = userCompany;
    if(user.app_metadata.roles) {
    	user.roles = user.app_metadata.roles;
    }
    if(user.app_metadata.companyId) {
    	user.companyId = user.app_metadata.companyId;
    }
    console.log('HELP!!!!!!!', user);
    callback(null, user, context);
    
  }).catch(err => {
    callback(err);
  });
}

```

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [March 26, 2021, 1:11pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/4 "2021-03-26T13:11:22Z")

</div>

You are missing the code to update the metadata in the profile:

```
 auth0.users
.updateUserMetadata(user.user_id, user.user_metadata)
.then(function () {
  callback(null, user, context);
})
.catch(function (err) {
  callback(err);
});

```

John

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 29, 2021, 8:47am UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/5 "2021-03-29T08:47:29Z")

</div>

Thanks for helping on this one John!

---

<div class="post-metadata">

**Author:** ![oflores2313](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oflores2313/32/28356_2.png) [@oflores2313](https://community.auth0.com/u/oflores2313)\
**Post date:** [March 29, 2021, 2:08pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/6 "2021-03-29T14:08:00Z")

</div>

Thank you John!!!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 30, 2021, 12:33pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/7 "2021-03-30T12:33:19Z")

</div>

We are here for you!

---

<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:** [April 14, 2021, 12:33pm UTC](https://community.auth0.com/t/rule-not-updating-my-app-metadata-but-in-debug-it-works/60009/8 "2021-04-14T12:33:42Z")

</div>

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