auth.api.hasPermission

I am having an issue with the hasPermission that it is not being recognized and is not a function of auth.api. I confirmed my version and checked the auth-client and auth setup. Any ideas?
10 Replies
LightTab2
LightTab24w ago
Could not reproduce on the latest release Can you share your auth setup? I assume you want to use organization plugin, so you need to pass it to the plugins array:
import { organization } from "better-auth/plugins"

export const auth = betterAuth(
{
...options,
plugins: [
organization()
],
});

// seen
auth.api.hasPermission(ctx);
import { organization } from "better-auth/plugins"

export const auth = betterAuth(
{
...options,
plugins: [
organization()
],
});

// seen
auth.api.hasPermission(ctx);
Ikillu578
Ikillu578OP4w ago
Here is my client and auth setup
Ping
Ping4w ago
you're type asserting the returnType of better-auth which overwrites the types. I assume you're doing this because you were running into ts issues before, so I would double check to make sure you disabled declaration, declarationMap, & composite in your tsconfig (and make strict: true)
Ikillu578
Ikillu578OP4w ago
That fixed it. I am fairly new to TS what are those compiler options? I am building a monorepo and I am using turbo and those were set when I started a new project. @Better Auth What is the schema for the dyamica access control? Also why can i not use authClient.organization.createRole to create a role it states its a 404 when trying to do dynamic access control
Ping
Ping4w ago
Does it provide anything in the logs?
Ikillu578
Ikillu578OP4w ago
Not all it gives is the 404 error POST /api/auth/organization/create-role 404 in 2692ms
Ping
Ping4w ago
You shouldn't be getting 404 if you've enabled it, do other org endpoints work?
Ikillu578
Ikillu578OP4w ago
It was a weird error. I figured it out I just redid both my auth.ts and auth-client.ts

Did you find this page helpful?