I am new to Auth0 and am working through a somewhat basic starter project just to get the hang of things. It is a basic social media project that consists of Auth0 (obviously), a React app on the frontend, and a Node.js GraphQL backend API. I am confused on how to relate user profile information to application data.
For example, given that I am using GraphQL, I want to be able to make a simple request that fetches a list of posts and the corresponding user that created the post.
The way I see it is there are two options. One, I keep a user’s table in my database that holds a user’s basic information such as id, username, first name, last name, etc. Then, on the GraphQL query, I can fetch the user’s information from the database easily. The other option is to not store the user’s information, and instead, make a request to the Auth0 management API to get user information.
In either case, I see a big issue. With the local user table, how do I keep this information in sync with the user’s information in Auth0? I could update the user’s data every time they make a request with my Node API, but isn’t this expensive to do on each request? If I use the management API, I then have to reach out to the rest API for each user which can be very expensive for a GraphQL request.
For both scenarios, what if a user gets deleted? How do I propagate these changes to my database so that their posts and any other data gets deleted.
In general, I am looking for a best practice to associate a user’s information to their data in my database and how I handle issues of keeping data in sync when a user updates their data or deletes their account. Thanks for any help.
Note - I do not wish to use the custom database feature.