Adding simple role to User Schema
hi guys! im having a little issue with adding a role to my User schema. I'm using Prisma and i wanted to add a role property to the User schema. It all works well, until i need to use the authClient.useSession() hook. I get the session off of it, but when trying to access the session.user.role property, it says there is no role property on it.
What i've already tried:
- Adding aditionalFields property to the better auth instance
- Adding the inferAdditionalFields plugins, both ways suggested in here: https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client
- Regenerated my Prisma client
I didnt want to include that whole admin plugin for roles since i dont think theres need for it in my simple app. I believe just an "Admin", "Customer" or "Support" role column on the User schema will do.
But if theres no better way to do it, i'll try that option.
TypeScript | Better Auth
Better Auth TypeScript integration.

Solution:Jump to solution
alright, i'll summarize the fix in here for anybody who happens to have the same issue in the future:
To add a custom field to your User schema:
1. In your auth.ts file, add the user.additionalFields property: (dont mind the prismaAdapter or socialProviders, these are specific to my project)...
11 Replies
Have you looked into the customSession plugin?
Session Management | Better Auth
Better Auth session management.
hey Max! thanks for the reply! Let me have a look at it
yeah, apparently it doesnt have anything to solve it. The issue is that im trying to access a newly added property to the User schema as in session.user.role
but it doesnt recognizes it
then inside a client component, i do:
and try to access the user role from the session: but TS tells me theres no role on the user object I tried adding the aditionalFields property in the auth.ts file:
and try to access the user role from the session: but TS tells me theres no role on the user object I tried adding the aditionalFields property in the auth.ts file:
db synced with schema after adding that custom field?
yes, Prisma Studio shows me that column is already in the database
can you show me your authClient config?
You need the
inferAdditionalFields client pluginPerfect! That solved the problem
My mistake was that I added the plugin on the auth instance, rather than on the auth-client instance
Solution
alright, i'll summarize the fix in here for anybody who happens to have the same issue in the future:
To add a custom field to your User schema:
1. In your auth.ts file, add the user.additionalFields property: (dont mind the prismaAdapter or socialProviders, these are specific to my project)
2. in your auth-client.ts file, add the inferAdditionalFields plugins:
3. From there, any additional property you add to the User schema, you'll need to include it on the user.additionalFields property from step 1 and they should get automatically picked up when you fetch the user.
Thank you guys for the help