Client not inferring customerSession type
I am unable to get the client to get the type of the customSession object.
Here is my backend code
and my client code
The permissions, teams, roles and user.accessLevel are not referred to on the client. I am using betterAuth 1.3.1


14 Replies
This is how i am exporting Auth from the backend.

@Better Auth any input on this?
Hey there! Could you clarify what you’re referring to? There have been several common topics lately—ranging from framework integrations (like Remix or Expo [1], [10]), to how custom additional fields work with the input property [2], or even suggestions for a debug mode [19]. Let me know which area you’d like to discuss, and I’ll be happy to dive in with more details!
Sources:
1. Remix Integration | Better Auth
10. Expo Integration | Better Auth
2. TypeScript | Better Auth
19. is better-auth has debug mode like next-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Remix Integration | Better Auth
Integrate Better Auth with Remix.
@Ping Can you please help me with this one
@P1NKPR0 Are you working on a monorepo workspace?
Yes i am
@P1NKPR0 Can you help me test if you still run into the same issue if you were to create the authClient in the same file as the
auth.ts and checked the type on useSession in that file tooHaving the same issue in a turbo monorepo. Creating the auth client in the same file does return the full session info for me.
lol...I love coding. I found the issue. Being that we have a strict set to false for our backend (gradual js to ts migration) one of the custom methods we have in the sever better-auth instance had a type error and that seems to have been what was causing the issue. @P1NKPR0 if you are still having this issue check if you have type errors that are being surpressed.
When i call getSession on the backend, it does include the custom session variables. but on the frontend, it's still not getting the types.
@kingitaj to your point i made sure both have strict mode on and no other issues with better-auth
The values are returned on the frontned but the types are not inferred

I found the issue but what could be causing it?
if i specify "as string" for the env variables under socialProviders, customSessionClient infers the correct types on the frontend.

@Ping any updates on this?
@Max i am still having issue with this, can you please point me towards fixing it
i found an issue also with trustedOrigins, the type needs to be specified for it to work properly, if not, it will break.
even though, allowedHosts is already an array of string. but i needed to specify the type again.
what could be causing this? it took me so long to get to the bottom of it

Can you show me how you're exporting the
Auth type?Its based on Bun's monorepo. It looks like i fixed the issue with the strict type for trustedOrigins.
I had the same issue with another project, which were the initial images uploaded. for that i fixed it by also strcit typing the env variables

