User-Data model with third party authentication


I am following this tutorial

And I want to build a user - data model, where users can upload private data i.e. only accessible by themselves. However, I am using a third party authentication service, and don’t have a proper user model in prisma.

What is a good way to solve it?

  1. Should I have a User model that is basically a copy of the third service provider?
  2. Is it just enough to associate an userId with the data model, and make sure to always filter for it?

I recommend having a user model that copy some information you want from the third service provider and the userId from this provider, this way you are more independent if you ever want to change provider.

Replacing the relation to a user by just the userId from your auth provider can also work, if it’s what you need.

1 Like

I’ve done something like this Best practices for external auth and db foreign-key to user? - #2 by mfosker

1 Like

To add to this I have a couple projects where I used Clerk and initially thought I’d just pass user info around via that and their APIs they expose to edit either public or private metadata info.

In practice and real world however, my lookups were faster and smoother experience so I use Clerk to get a session going with their auth, and then made my own user data model where it’s less private info and more like dashboard settings and things.

Clerk then can have webhooks made. I use that to pick the payload type that includes info I want, and send it to a redwood function (on Vercel this ends up being a serverless function) that will add clerk userId to a field in my own user data object as well as whatever info I want from that payload which can be customized to some degree.

That way I sort of detach the user data I want and isn’t really sensitive info, but more like game state from the auth parts.

That’s basically my way of doing that second step from above advice have a User Profile built off the unique Clerk userId.

I then load it in with a redwood Cell built to query that User Profile given the Clerk session context and use currentUser to get the info

1 Like