maxis-code-logo

Maxis Code

Set app metadata on the user in Auth0


Set app metadata on the user in Auth0-cover-image
Photo by: Joshua Sortino - https://unsplash.com/@sortino

I was a bit confused about how to get info from app_metadata onto the user that is returned in useUser / getSession. This is how.

Go to a User in Auth0

  • User Management -> Users

Add a piece of data to the app_metadata section

1{ 2 "your_data": "this is my data" 3}

Create a Rule

  • Auth Pipeline -> Rules
  • Hit the Create button
  • Choose empty rule

Add this function

1function addYourData(user, context, callback) { 2 user.app_metadata = user.app_metadata || {} 3 context.idToken['https://pick.some.namespace/your_data'] = 4 user.app_metadata.your_data 5 callback(null, user, context) 6}

Now in your app when you useUser or getSession you will see this is my data under the key https://pick.some.namespace/your_data on the user object.

Comments


Please sign in to view and leave comments...