mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: reconcile documentation guarantees and enforcement (OM-15)
This commit is contained in:
1 parent
6c878ae79a
commit
dcb50b7e0f
28 files changed
+461
-128
No files matched your search
@@ -1,10 +1,15 @@
|
||||
import { betterAuth } from 'better-auth'
|
||||
import { APIError } from 'better-auth/api'
|
||||
import { passkey } from '@better-auth/passkey'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { ENV } from '@opencode-manager/shared/config/env'
|
||||
|
||||
export type AuthInstance = ReturnType<typeof createAuth>
|
||||
|
||||
export function isAdminConfigured(): boolean {
|
||||
return !!(ENV.AUTH.ADMIN_EMAIL && ENV.AUTH.ADMIN_PASSWORD)
|
||||
}
|
||||
|
||||
export function createAuth(db: Database) {
|
||||
const socialProviders: Record<string, { clientId: string; clientSecret: string }> = {}
|
||||
|
||||
@@ -44,6 +49,17 @@ export function createAuth(db: Database) {
|
||||
autoSignIn: true,
|
||||
},
|
||||
socialProviders: Object.keys(socialProviders).length > 0 ? socialProviders : undefined,
|
||||
databaseHooks: {
|
||||
user: {
|
||||
create: {
|
||||
before: async (user, context) => {
|
||||
if (isAdminConfigured() && (context?.request || user.email.toLowerCase() !== ENV.AUTH.ADMIN_EMAIL!.toLowerCase())) {
|
||||
throw new APIError('FORBIDDEN', { message: 'Registration is disabled' })
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
passkey({
|
||||
rpID: ENV.AUTH.PASSKEY_RP_ID,
|
||||
|
||||
Reference in new issue
Block a user