refactor: replace admin bootstrap script with first-run setup

This commit is contained in:
2026-06-06 00:02:43 +01:00
parent b435a92da8
commit 5be93c65ea
7 changed files with 210 additions and 114 deletions
+3 -18
View File
@@ -32,22 +32,14 @@ Apply database migrations:
DATABASE_URL=file:local.db pnpm db:migrate
```
Create an initial admin user:
```sh
ADMIN_EMAIL=admin@example.com \
ADMIN_PASSWORD='change-me' \
ADMIN_NAME='Administrator' \
DATABASE_URL=file:local.db \
pnpm admin:create
```
Start the development server:
```sh
pnpm dev
```
Open `http://localhost:5173/login`. If no Better Auth users exist yet, Clearity shows a first-admin setup form instead of the normal sign-in form. Submitting it creates the initial user with the default Better Auth `admin` role and signs you in.
Useful development commands:
```sh
@@ -68,13 +60,6 @@ Required:
- `ORIGIN`: Public app origin, for example `http://localhost:5173` locally or `https://clearity.example.com` in production.
- `BETTER_AUTH_SECRET`: Secret used by Better Auth.
Admin bootstrap script:
- `ADMIN_EMAIL`: Email address for the admin account.
- `ADMIN_PASSWORD`: Password for the admin account.
- `ADMIN_NAME`: Optional display name. Defaults to `Administrator`.
- `ADMIN_OVERWRITE`: Set to `1` to update an existing admin user.
## Database
The application schema lives in `src/lib/server/db`. Drizzle migration files live in `drizzle`.
@@ -163,4 +148,4 @@ Preview the built Worker locally:
pnpm preview
```
Create the first production admin user by running the admin script against the production database connection before exposing the app to users.
Create the first production admin by opening `/login` after migrations have run. The setup form is only shown while the Better Auth `user` table is empty.