ADMIN plugin not working

hey! i didn't want to open a gh issue just yet because maybe i'm doing something wrong, but i just integrated the admin plugin and found that nothing seems to be working for me. 1. signing up a new user doesn't set any default role value. 2. trying to impersonate (manually created users) or create user with auth-client gives 404 if someone could help me, i will greatly appreciate it. also lmk if you need any extra info. thanks ☺︎
4 Replies
oof2win2
oof2win22w ago
hiya - i just had similar issues. make sure that you expose the correct fields in the database to better-auth. for 1, i just set the default role to user. not sure if it's the right approach, but better-auth can always change it to something else if necessary
oscar
oscarOP2w ago
hi. i believe i have the correct fields. this are the ones i added.
model User {
id String @id
name String
email String
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime

role String?
banned Boolean?
banReason String?
banExpires DateTime?

sessions Session[]
accounts Account[]

@@unique([email])
@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

impersonatedBy String?

@@unique([token])
@@map("session")
}
model User {
id String @id
name String
email String
emailVerified Boolean
image String?
createdAt DateTime
updatedAt DateTime

role String?
banned Boolean?
banReason String?
banExpires DateTime?

sessions Session[]
accounts Account[]

@@unique([email])
@@map("user")
}

model Session {
id String @id
expiresAt DateTime
token String
createdAt DateTime
updatedAt DateTime
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

impersonatedBy String?

@@unique([token])
@@map("session")
}
bekacru
bekacru2w ago
If 404 is sent, that means the admin plugin isn't properly added on the server.
oscar
oscarOP2w ago
hi. this is my auth server file.
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { admin } from "better-auth/plugins";
import { db } from "@/server/db";

export const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
},
rateLimit: {
enabled: true,
maxRequests: 10,
perInterval: 60 * 1000, // 1 minute
},
providers: {
plugins: [admin(), nextCookies()],
},
});

export type Session = typeof auth.$Infer.Session;
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { admin } from "better-auth/plugins";
import { db } from "@/server/db";

export const auth = betterAuth({
database: prismaAdapter(db, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
},
rateLimit: {
enabled: true,
maxRequests: 10,
perInterval: 60 * 1000, // 1 minute
},
providers: {
plugins: [admin(), nextCookies()],
},
});

export type Session = typeof auth.$Infer.Session;

Did you find this page helpful?