refactor(auth): reset the admin and count users through the Better Auth adapter

The admin password reset and the first-user check read and wrote the
Better Auth tables with raw SQL, so session delete hooks never ran on the
reset path.

- the admin is found with findUserByEmail and its credential account is
  updated by id with the configured password hasher
- sessions are removed with deleteUserSessions, which runs the session
  delete hooks
- a missing credential account logs a warning instead of updating nothing
- /api/auth-info/config counts users through the adapter
This commit is contained in:
Chris Scott committed 2026-10-24 19:26:21 -04:00
1 parent b9d8d18124
commit cbe4f7ed9e
4 files changed
+186 -131

No files matched your search

+2 -2
View File
@@ -244,7 +244,7 @@ try {
await gitAuthService.initialize(ipcServer, db)
logger.info(`Git IPC server running at ${ipcServer.ipcHandlePath}`)
await syncAdminFromEnv(auth, db)
await syncAdminFromEnv(auth)
opencodeServerManager.setDatabase(db)
detectSandboxCapability()
@@ -389,7 +389,7 @@ const previewSessionStore = new PreviewSessionStore()
const previewAvailability = createPreviewAvailability(false)
app.route('/api/auth', createAuthRoutes(auth))
app.route('/api/auth-info', createAuthInfoRoutes(auth, db))
app.route('/api/auth-info', createAuthInfoRoutes(auth))
app.route('/api/health', createHealthRoutes(db, openCodeSupervisor))
app.route('/api/mcp-oauth-proxy', createMcpOauthProxyRoutes(openCodeClient, requireAuth))