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

+1 -1
View File
@@ -78,7 +78,7 @@ describe('createAuth', () => {
body: { email: 'other@example.com', password: 'test-password', name: 'Other' },
})).rejects.toThrow('Registration is disabled')
await syncAdminFromEnv(auth, db)
await syncAdminFromEnv(auth)
const response = await auth.handler(new Request('http://localhost:5173/api/auth/sign-in/email', {
method: 'POST',
headers: { 'content-type': 'application/json', origin: 'http://localhost:5173' },