inferring types on the client, based on plugins added on the server

I have a monorepo, with the admin plugin added to the server initialization of betterAuth. I was expecting the additional user properties, like role would be accessible from session.user. Here's my server code:
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
schema,
usePlural: true,
}),
emailAndPassword: {
enabled: true,
},
plugins: [admin()],
});
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
schema,
usePlural: true,
}),
emailAndPassword: {
enabled: true,
},
plugins: [admin()],
});
And this is the auth client on the frontend:
export const authClient = createAuthClient({
plugins: [inferAdditionalFields<typeof auth>()],
});
export const authClient = createAuthClient({
plugins: [inferAdditionalFields<typeof auth>()],
});
Then, when trying to access the role property from the session.user object, I get:
Property 'role' does not exist on type '{ id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }'.ts(2339)
Property 'role' does not exist on type '{ id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }'.ts(2339)
FWIW, I can do the following on the client, and I get the actual shape of User:
type Session = Awaited<ReturnType<typeof auth.api.getSession>>;
type User = NonNullable<Session>['user'];
type Session = Awaited<ReturnType<typeof auth.api.getSession>>;
type User = NonNullable<Session>['user'];
What's the right approach to get the User shape in the client side in the session object?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?