Next.js Discord

Discord Forum

Linking accounts next-auth

Unanswered
Standard Chinchilla posted this in #help-forum
Open in Discord
Standard ChinchillaOP
How do you guys handle account linking? Like I am trying to figure out to link google calendar account but I am unsure how would I go ahead and structure my schema? Do I create a LinkedAccounts and attach it to the User model or the Account model inside next-auth

24 Replies

Standard ChinchillaOP
If I add it to the Account then I need to fetch Account manually I guess where as I can get the User fields directly through the getServerSession
I am confused how should go around by structuring my schema in this case
@Standard Chinchilla i am not sure what u wanna do but something like this?

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]
  calenderEvents CalenderEvents[] <--- here
}

assuming one user has many calender events.
Standard ChinchillaOP
yea but first I need to link google calendar
model CalenderEvents {
id String @id @default(cuid())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId String?
}
Standard ChinchillaOP
Because I am not sure if I wanna handle yk calendar events myselff
since it puts me into handling cron jobs and everything
sorry focus on one question at moment. it sounds different story
Standard ChinchillaOP
yea I mean i was talking about your calendar events part only
I dont want that
Talking about rn handling linking accounts
like linking a users google calendar
to the app
But the problem is i am unsure whrther i should touch User model or account model
I am unable to find explanation on why Account exists?
Is it even necessary?
sorry, isn't you who defined tables in schema.prisma file?
Standard ChinchillaOP
nayy
I mean these are by next auth
using prisma adapter
it is obvious from the schema. One user can have many OAuth such as Google, GitHub and so on. user.email is optional.
Standard ChinchillaOP
yea so I think I shpuld put everything related to user in user model only
i.e. linked accounts for api usage
?