I have a NextJs application using the @auth0/nextjs-auth0 library. I am trying to store some metadata within user’s profile ( e.g. app_metadata : { id: 123} ) with an axios call. How can I get the management_api_key?
I have manually put some metadata using the dashboard → User Management → Users → Metadata. And I have set a AUTH0_SCOPE=‘openid email profile read:current_user’ in my .env.local within my NextJs project. However when i console log the “user” using the useUser hook, I cannot see the user_metadata.
So how can I create and read user metadata in my NextJs application? Thank you <3
I am sorry, I am still very new to this. Would you be able to give me some more instruction please? Which method, out of those two, do you recommend more? Also am I supposed to fetch the access token within my NextJs app under pages/api/auth, or I should be setting up a backend route and call that api from the front end?
I would suggest option 2, to use the Auth0 Node.js Library to automatically get Access tokens for the Management API.
The former. Using the Auth0 Node.js library, you can make requests to read and create app_metadata without being concerned with getting a token. After instantiating the ManagementClient class, you will automatically have an access token that you can make requests with the Management API.
Lastly, please make sure your audience value matches the Management API identifier found on your Auth0 Dashboard. Generally in the format https://YOUR_DOMAIN.REGION.auth0.com/api/v2/.
Please let me know if there’s anything else I can do to help.