Jïns
Jïns
Explore posts from servers
BABetter Auth
Created by Jïns on 4/26/2025 in #help
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"];
4 replies
BABetter Auth
Created by Jïns on 4/25/2025 in #help
Extend type user
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ newEmail, url }) => {
///
},
},
additionalFields: {
truc_de_con: {
type: "string",
nullable: true,
},
},
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ newEmail, url }) => {
///
},
},
additionalFields: {
truc_de_con: {
type: "string",
nullable: true,
},
},
I added an additionalFields but when I import type { User } from "better-auth"; I get only the default form
(alias) type User = {
id: string;
name: string;
email: string;
emailVerified: boolean;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
}
(alias) type User = {
id: string;
name: string;
email: string;
emailVerified: boolean;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
}
19 replies
BABetter Auth
Created by Jïns on 4/20/2025 in #help
Issue with Better-Auth Email Verification
Hey everyone, I'm having an issue with email verification in better-auth. When a user changes their email: The email address gets updated correctly in the database BUT the verification email is not being sent Here's the relevant code:
// auth.js config
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url, token }) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);

await sendEmail({
to: newEmail,
subject: "Vérification d'email",
text: `Cliquez sur ce lien pour vérifier votre nouvelle adresse email: ${url}`,
});
},
},
// ...
}

// action.js (server action)
export async function updateUserEmail(email: string) {
await auth.api.changeEmail({
body: {
newEmail: email,
callbackURL: `/`,
},
headers: await headers(),
})
}
// auth.js config
user: {
changeEmail: {
enabled: true,
sendChangeEmailVerification: async ({ user, newEmail, url, token }) => {
console.log("sendChangeEmailVerification", user, newEmail, url, token);

await sendEmail({
to: newEmail,
subject: "Vérification d'email",
text: `Cliquez sur ce lien pour vérifier votre nouvelle adresse email: ${url}`,
});
},
},
// ...
}

// action.js (server action)
export async function updateUserEmail(email: string) {
await auth.api.changeEmail({
body: {
newEmail: email,
callbackURL: `/`,
},
headers: await headers(),
})
}
The console.log shows nothing when changing email, and no verification email is sent. The email does update in the database though. Any ideas what might be wrong with my implementation?
9 replies