Relations between Clerk Users with Prisma db
I've been using T3 for a few months now with nextAuth... I'm attempting to use Clerk with "t3-turbo-and-clerk". The part I'm getting real tripped up on is making relations between my prisma db and Clerk Users. With create-t3 / nextAuth, that nextAuth User table is in my schema and making relations is pretty brainless, but with Clerk hosting the Users, I'm not quite sure how to make that relation.
Felt like a silly question to ask, but hopefully makes sense and someone can point me in the right direction! Thanks!
6 Replies
Clerk returns a Authentication Object when using it with Next. That has the Clerk userId. https://clerk.dev/docs/nextjs/authentication-props
Whether you want to save a 'local' copy of that into a sort of Accounts table if up to you, or just rely on that info from Clerk.
@jjrise were you able to start using it? I'm starting a new project on T3 now and wondering if I should go straight with Clerk or rather with NextAuth and all auth data in my db (on PlanetScale) 🙂
Appreciate!
I completely transitioned to Clerk now. I’m actually using it in turbo repo with 2 apps sharing the same Clerk application
So I guess it's worth it 😁 I'm wondering because I'm rewriting an app where there is already a DB with existing users and the question is if I'll be able to easily associate them with Clerk now, and how do I approach this (I saw there is an option to import existing users to Clerk DB somehow).
Thanks for answering anyway! Have a great day
Yep so I had some issues, but mostly schema issues on my end, not necessarily clerk issues
There are some extra tables in your schema that are particular to nextauth. I ultimately removed those and added a field ‘clerkuserid’ to my Users table.
And added @unique to that field and kinda ignore the normal User ID for relations
Sorry driving now so hard to message but hopefully makes sense
Totally, thanks a lot!
Drive safely 🙂