feat(api): add better-auth admin plugin + close public sign-up (migration 0002)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { betterAuth } from 'better-auth';
|
||||
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
||||
import { bearer } from 'better-auth/plugins';
|
||||
import { admin, bearer } from 'better-auth/plugins';
|
||||
import { db } from './db/client';
|
||||
import * as schema from './db/schema';
|
||||
import { env } from './env';
|
||||
@@ -13,6 +13,7 @@ export const auth = betterAuth({
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
requireEmailVerification: false,
|
||||
disableSignUp: true, // admin creates users; see docs/plans/phase-2-accounts-roles.md
|
||||
},
|
||||
plugins: [bearer()],
|
||||
plugins: [bearer(), admin({ defaultRole: 'worker', adminRoles: ['admin'] })],
|
||||
});
|
||||
|
||||
@@ -11,6 +11,10 @@ export const user = sqliteTable('user', {
|
||||
email: text('email').notNull().unique(),
|
||||
emailVerified: integer('email_verified', { mode: 'boolean' }).default(false).notNull(),
|
||||
image: text('image'),
|
||||
role: text('role'),
|
||||
banned: integer('banned', { mode: 'boolean' }),
|
||||
banReason: text('ban_reason'),
|
||||
banExpires: integer('ban_expires', { mode: 'timestamp_ms' }),
|
||||
createdAt: integer('created_at', { mode: 'timestamp_ms' })
|
||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||
.notNull(),
|
||||
@@ -34,6 +38,7 @@ export const session = sqliteTable(
|
||||
.notNull(),
|
||||
ipAddress: text('ip_address'),
|
||||
userAgent: text('user_agent'),
|
||||
impersonatedBy: text('impersonated_by'),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: 'cascade' }),
|
||||
|
||||
Reference in New Issue
Block a user