user role / admin plugin
@Better Auth why is
and not as an array of literal strings?
my auth config:
user.roleuser.role typed as role?: string | null | undefinedrole?: string | null | undefinedand not as an array of literal strings?
my auth config:
import { betterAuth, type BetterAuthOptions } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { getDb, schema } from "~/db";
import { adminPlugin } from "./plugins";
export function getAuth(env: Cloudflare.Env) {
const db = getDb(env);
return betterAuth({
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BASE_URL,
database: drizzleAdapter(db, {
provider: "sqlite",
schema,
transaction: false,
}),
socialProviders: {
github: {
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
},
discord: {
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
},
},
account: {
accountLinking: {
enabled: true,
allowDifferentEmails: false, // TODO - enable later
},
},
plugins: [adminPlugin],
} satisfies BetterAuthOptions);
}
export type AuthInstance = ReturnType<typeof getAuth>;
export type SessionAndUser = AuthInstance["$Infer"]["Session"];
export type Session = SessionAndUser["session"];
export type User = SessionAndUser["user"];
export type OAuthProvider = keyof AuthInstance["options"]["socialProviders"];import { betterAuth, type BetterAuthOptions } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { getDb, schema } from "~/db";
import { adminPlugin } from "./plugins";
export function getAuth(env: Cloudflare.Env) {
const db = getDb(env);
return betterAuth({
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BASE_URL,
database: drizzleAdapter(db, {
provider: "sqlite",
schema,
transaction: false,
}),
socialProviders: {
github: {
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
},
discord: {
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
},
},
account: {
accountLinking: {
enabled: true,
allowDifferentEmails: false, // TODO - enable later
},
},
plugins: [adminPlugin],
} satisfies BetterAuthOptions);
}
export type AuthInstance = ReturnType<typeof getAuth>;
export type SessionAndUser = AuthInstance["$Infer"]["Session"];
export type Session = SessionAndUser["session"];
export type User = SessionAndUser["user"];
export type OAuthProvider = keyof AuthInstance["options"]["socialProviders"];type User = {
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
emailVerified: boolean;
name: string;
image?: string | null | undefined;
banned: boolean | null | undefined;
role?: string | null | undefined;
banReason?: string | null | undefined;
banExpires?: Date | null | undefined;
}type User = {
id: string;
createdAt: Date;
updatedAt: Date;
email: string;
emailVerified: boolean;
name: string;
image?: string | null | undefined;
banned: boolean | null | undefined;
role?: string | null | undefined;
banReason?: string | null | undefined;
banExpires?: Date | null | undefined;
}