Can I add email address to the access token when calling an api?

I’m following this guide: The Complete Guide to React User Authentication with Auth0
Everything works, but I need to get a few basic details about the user in the api code, primarily the user’s email address.

I guess my question is:

  • Is there any way to affect the data in the access token retrived here? const { getAccessTokenSilently } = useAuth0(); Can I somehow indicate that I’d like to add the user’s emai added to that token?
  • What is otherwise the preferred method for an api to get more information (such as the user’s email) about the calling user?
1 Like

Hi @trondhindenes,

Thanks for reaching out to the Auth0 Community.

Yes! I recommend using the Add email to access token rule to add the user’s email address to the access token. Navigate to your Dashboard > Auth0Pipeline > Rules > Create and select the Add email to access token rule.

For the complete list of User Object Properties, take a look at this documentation: https://auth0.com/docs/rules/user-object-in-rules

After doing so, you can use the Access Token to access your API that contains information about the user’s email address in the payload.

Please let me know if this addresses your questions.

Thank you.

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.