Access user_metadata from a SPA


I have been struggling a great deal to understand how to access the user_metadata.

The use case is as follows:

After a user has signed up to the system, we wish to retrieve additional information from the user. To solve this we have added a flag in the user_metadata in the “Pre User Registration” flow with the following value:

“post_registration_pending”: true

in order to create business logic in the frontend to display a form for the user to input further data not included in the sign up process.

From what I could read from the docs, I should be able to retrieve the metadata via the Management API at the endpoint "/api/v2/users/{id} from the client

I do however get 401 Unauthorised.

I could read from this post, that in order to use the Management API I needed ask Auth0 for an access token.

When I access the go the the Auth0 dashboard and go to Applications/API/Test I do get a successful access_token, however, when I try to do the same thing in the client I get a CORS error.

What can I do here? Am I even on the right track in terms of achieving what should be a pretty simple functionality?

Hi @gandersen,

Yes, while it is possible to access the Management API from a SPA, they are issued in the context of the user who is currently signed in to Auth0.

In this case, I recommend following our Get Management API Access Tokens for Single-Page Applications documentation for more information.

Alternatively, you could append the user_metadata as a custom claim to the access token.

Please let me know if you have any questions.