Add id of relation to user obj

Is it possible to access the company id in the session user?

model User {
  ....
  company Company?
  sessions Session[]
  accounts Account[]
  @@map("users")
}

model Company {
  id        String   @id @default(uuid())
  userId      String  @unique
  user        User    @relation(fields: [userId], references: [id], onDelete: Cascade)
}
Solution
Hello, you need to define an additional field in your auth config:
https://www.better-auth.com/docs/concepts/typescript#additional-fields

Then, you can access it via the customSession plugin:
https://www.better-auth.com/docs/concepts/session-management#customizing-session-response
Better Auth TypeScript integration.
Better Auth session management.
Was this page helpful?