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)
}
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...
TypeScript | Better Auth
Better Auth TypeScript integration.
Session Management | Better Auth
Better Auth session management.
Jump to solution
1 Reply
Solution
Ping
Ping2w ago
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
TypeScript | Better Auth
Better Auth TypeScript integration.
Session Management | Better Auth
Better Auth session management.

Did you find this page helpful?