Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auth0 - enriching data with user information

I need my API to return objects that contain some user info. For example: api/comment/123 needs to return:

{
    id: 123,
    author: {
         id: 'googleblahblah|123456789',
         name: 'James Bond'
    }
}

Normally I would just join the user and the comment table, though in this case I can't. My app's database stores the user id, though the name (and other user stuff) is stored in Auth0.

Obviously making an API call to Auth0 to 'enrich' objects on every API call is not plausible.

Do I cache all / some some user info on my app server? Have only the user ID in the API result and let the client enrich the data?

How do people handle this?

like image 389
nick Avatar asked Sep 23 '16 16:09

nick


1 Answers

I do not think there is an ultimate solution for this problem.

What I did was creating a user table with user id and user name in my own database. Whenever somebody logs via Auth0 in I would create or update the logged-in user information in that table with the OAuth token information.

After that you could join the tables as you stated.

like image 150
Arjen de Blok Avatar answered Nov 15 '22 17:11

Arjen de Blok