Hello, I need to get the authorized user’s app_metadata and I’m having quite a bit of difficulty doing so. I have read the following Auth0 doc pages:
- Metadata
- User Metadata in Rules
- User profile claims and scope
- Rules
- and several others
I still just don’t get it, but I think I’m close to understanding. It’s my understanding that I need to create a new rule to add scoped information to the context from the user profile - in my case I would be adding app_metadata. But when I try to test this rule on the “Edit Rule” page I get the error below:
function (user, context, callback) {
const namespace = ‘https://myapp.example.com/’;
//context.idToken[namespace + ‘favorite_color’] = user.favorite_color;
context.idToken[namespace + ‘preferred_contact’] = user.user_metadata.preferred_contact;
callback(null, user, context);
}
“ERROR: Cannot read property ‘preferred_contact’ of undefined”
The User object does not have the “user_metadata” object (nor does it have the “app_metadata” object). So right there the sample code in the “User profile claims and scope” doc page is not helpful and effectively wrong. It almost makes me think there is something wrong with my account? I’m using the “free” Auth0 account for now. It’s a “Generic Account” that I created from the Heroku app. Is it only the paid accounts that have metadata info in the User object? If that’s the case then that page of the docs should specify. Or maybe I need to login somehow to set my id_token in the session? But, again, the docs should specify that. there seems to be a lot of silent presumption in the docs on this particular subject and it’s forcing me to visit all the pages and tie it all together. Which, if my use case were somehow rare then it would be understandable. But these doc titles are specifically my use case and they still don’t seem to be able to just tell me how to accomplish my goals.
So thoughts? What am I doing wrong? I can post code, but I can’t even get the Rule Editor to work so I haven’t written much code in this regard yet, other than a simply *.userinfo() call which, of course comes back without any metadata info.
Thanks for any help. Auth0 is a fantastic product.