What is the best approach to associate user information in my backend API?


Hi Auth0 Team,

I am very new to Auth0 and I’m having trouble when and how to store information in my own db for the sake of data association.

One approach I thought of is, whenever User sends a request in my backend using a access token, I would use a middleware to check if the user exists in the db. If it does not, I will create a new one. There are several disadvantage with this approach:

  1. I do not get know the user email or name, because Access tokens doesn’t provide me that
  2. I have to query database to check for the user each time the user requests something

Is there any better approach? What if I want to store user name and email in my DB?

Hi @ahmedsadman.211,

Welcome to the Auth0 Community!

Creating the user if they don’t exist works fine if you applications allows for it.

You can use the user ID to associate data to the user in your backend DB. This ID is provided in the access token as the sub claim.

You can add custom claims to the tokens, including name and email. You could do this conditionally if it is a first login, or add it to every token. Up to you.

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