Session Management Type Inference
Hey everyone!
Need some help with Better Auth type inference for custom session data
I'm having an issue with TypeScript type inference when using customSession plugin with Better Auth. Here's my setup:
Client setup:
Server setup:
The Issue:
Works: When I call useSession() on the client, I get the full type with both:
Additional fields from user.additionalFields
Company data from my customSession
Doesn't work: Server-side type inference like:
The company property I'm adding in customSession isn't available in the inferred type on the server side (Which is where I want to define the type to use throughout the app), even though it works perfectly on the client after calling useSession().
Question: Is this expected behavior? Should custom session data only be available after calling useSession(), or am I missing something in my setup?
I'm following the docs here: https://www.better-auth.com/docs/concepts/session-management#customizing-session-response
Any insights would be super helpful!
I'm having an issue with TypeScript type inference when using customSession plugin with Better Auth. Here's my setup:
Client setup:
Server setup:
The Issue:
Works: When I call useSession() on the client, I get the full type with both:
Additional fields from user.additionalFields
Company data from my customSession
Doesn't work: Server-side type inference like:
The company property I'm adding in customSession isn't available in the inferred type on the server side (Which is where I want to define the type to use throughout the app), even though it works perfectly on the client after calling useSession().
Question: Is this expected behavior? Should custom session data only be available after calling useSession(), or am I missing something in my setup?
I'm following the docs here: https://www.better-auth.com/docs/concepts/session-management#customizing-session-response
Any insights would be super helpful!
