Unable to check permisions

When I do this
export async function updateUser(id: string, payload: Partial<User>) {
const canCreateProject = await authClient.admin.hasPermission(
{
permissions: {
product: ["create"],
},
},
{
headers: await headers(),
},
);

console.log("canCreateProject", canCreateProject);
}
export async function updateUser(id: string, payload: Partial<User>) {
const canCreateProject = await authClient.admin.hasPermission(
{
permissions: {
product: ["create"],
},
},
{
headers: await headers(),
},
);

console.log("canCreateProject", canCreateProject);
}
with an admin person its keeping console me this :
canCreateProject { data: null, error: { status: 0, statusText: '' } }
canCreateProject { data: null, error: { status: 0, statusText: '' } }
there is my permissions.ts
import { createAccessControl } from "better-auth/plugins/access";
import { adminAc, defaultStatements } from "better-auth/plugins/admin/access";

// Define your statements with all permissions
export const statements = {
...defaultStatements,
product: ["create", "update", "delete", "list"],
users: ["create", "update", "delete"],
} as const;

// Create access control with these statements
export const ac = createAccessControl(statements);

// Admin has all permissions
export const admin = ac.newRole({
...adminAc.statements,
product: ["create", "update", "delete"],
users: ["create", "update", "delete"],
});
import { createAccessControl } from "better-auth/plugins/access";
import { adminAc, defaultStatements } from "better-auth/plugins/admin/access";

// Define your statements with all permissions
export const statements = {
...defaultStatements,
product: ["create", "update", "delete", "list"],
users: ["create", "update", "delete"],
} as const;

// Create access control with these statements
export const ac = createAccessControl(statements);

// Admin has all permissions
export const admin = ac.newRole({
...adminAc.statements,
product: ["create", "update", "delete"],
users: ["create", "update", "delete"],
});
auth.ts
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),

emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {

},
},
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ newEmail, url }) => {
// Il faudrait ajouter ceci:

},
},
additionalFields: {
truc_de_con: {
type: "string",
nullable: true,
},
},
},
plugins: [
nextCookies(),
adminPlugin({
ac,
roles: {
admin: adminRole,
},
}),
],
});

export type Session = typeof auth.$Infer.Session;
export type User = (typeof auth.$Infer.Session)["user"];
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),

emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {

},
},
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ newEmail, url }) => {
// Il faudrait ajouter ceci:

},
},
additionalFields: {
truc_de_con: {
type: "string",
nullable: true,
},
},
},
plugins: [
nextCookies(),
adminPlugin({
ac,
roles: {
admin: adminRole,
},
}),
],
});

export type Session = typeof auth.$Infer.Session;
export type User = (typeof auth.$Infer.Session)["user"];
1 Reply
Jïns
JïnsOP4d ago
there is my auth-client.ts
import { createAuthClient } from "better-auth/react";
import { adminClient } from "better-auth/client/plugins";
import { ac, admin as adminRole } from "@/lib/permissions";
import { nextCookies } from "better-auth/next-js";
export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [
adminClient({
ac,
roles: {
admin: adminRole,
},
}),
nextCookies(),
],
});
import { createAuthClient } from "better-auth/react";
import { adminClient } from "better-auth/client/plugins";
import { ac, admin as adminRole } from "@/lib/permissions";
import { nextCookies } from "better-auth/next-js";
export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [
adminClient({
ac,
roles: {
admin: adminRole,
},
}),
nextCookies(),
],
});
Someone has an idea ?

Did you find this page helpful?