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?
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);
});
}