Auth0 Home Blog Docs

I'm not able to Add Persistent Attributes To The User


#1

Hello, I’m trying to add a user data to my app delevloped with Angular 5.
I add the login with auth0. I’d like to add some infos when I login like company name.
I follow this link, but i’m not able…

I insert the data on user_metadata
“Company”:“Example”

I create a new rule clicking on “Add Persistent Attributes To The User” with the following code:

function (user, context, callback) {
  user.user_metadata = user.user_metadata || {};
  user.user_metadata.cocompanylor = user.user_metadata.company || 'Error';
  context.idToken['https://example.com/favorite_color'] = user.user_metadata.company;

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

All works but I saw https://example.com/favorite_color and I see the result if I print con console all the profile.
But I want to assign property Company to my local variable…
I tried this.profile.user_metadata but it doesn’t work
How can I do that?


#2

You’re assigning the value of user.user_metadata.company to a custom claim named https://example.com/favorite_color so in order to access that value on the client application you would have to do something like:

var company = this.profile["https://example.com/favorite_color"];

#3

Hello, thanks for your reply!

But I still have problems… the function overwrite the value on user_metadata and company become Error.

also another question: how can i use var_name istead of a url like: https://example.com/favorite_color ?

thanks