Typescript not seeing role as a valid attribute
I'm trying to check if a user is admin in order to access admin only pages.
To do this I have this code, it works fine.
But typescript says role dosen't exist
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)
I know the role comes from better-auth, it's the default admin role. Why can't typescript see it?
auth.ts
https://pastebin.com/J1TV7T8SPastebin
import { betterAuth } from "better-auth";import { nextCookies } fro...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
2 Replies
I dont think better auth has default role , we need to extend the default session to add role
did you add that in the auth.ts file
and for typescript you need add the additional role in the authClient too
I probably just forgot that I added it them, weird that I see it in the user object in console log
I tried something like this, in auth.ts
in authClient.ts
But I still get the same TS error
I also tried adding it manually to authClient, but still get the same error