User role property in Organization plugin

Hey, I'm trying to setup the Organization plugin and I want to only let admin/superadmin roles be able to create new orgs using the allowUserToCreateOrganization However, the role property doesn't seem to exist on the user type, even though I have added the admin plugin and migrated the changes on DB. But I still get this error: Property 'role' does not exist on type '{ id: string; name: string; emailVerified: boolean; email: string; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }'.ts(2339)
7 Replies
JackTheRipper
JackTheRipperOP2mo ago
Also, here is the code. Sorry it didn't went through the first time
No description
No description
Ping
Ping2mo ago
Yeah that's a common issue in Better auth where existing plugins or schemas won't effect the type def of users or sessions in function properties of the auth config. In most cases you can ignore the type inference and assume that it exists, so if you think this is the case you can just do a if("role" in user) sort of thing to check
Nathan
Nathan2mo ago
Hey guys, nearly the same issue here. I'd like to be able to create a new "admin" (from admin plugin) user when I use authClient.signUp.email(). However, the role will be always set to default user role. Any idea ?
Bailenz
Bailenz2mo ago
That is for using a finite set of roles and permissions that have been defined during the requirement phase? You don’t have dynamic roles?
Nathan
Nathan2mo ago
I just set a defaultRole (which is the same as the default one I think) and the list of admin roles. In organisation. My autClient has the 2 client plugins set up. Last screenshot is a Button and when I click on it, my user is created with the role "user" (the default role I've inserted). Any idea ?
No description
No description
No description
Timur
Timur2mo ago
Hi @JackTheRipper and @Ping I created this PR to suppress the ts error https://github.com/better-auth/better-auth/pull/3600
Petr Bela
Petr Bela2mo ago
Shouldn't you just be using the https://www.better-auth.com/docs/plugins/admin ?
Admin | Better Auth
Admin plugin for Better Auth

Did you find this page helpful?