Skip to content

Commit e3cd45f

Browse files
elemdosclaude
andcommitted
Keep gating setup until an account actually exists
Visiting /admin/setup latched setupCompleted=true before any superuser was created, so a second visit to the bare domain skipped the gate and landed on /admin/auth — a dead end on a never-set-up instance. Only latch once a real superuser exists; until then, redirect every non-setup admin page back to setup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 056f2ba commit e3cd45f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/admin.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@ func RegisterAdminApp(pb *pocketbase.PocketBase) error {
5757
setupRequired := superuserCount == 0
5858
isSetup := requestEvent.Request.URL.Path == "/admin/setup"
5959
isFile := path.Ext(requestEvent.Request.URL.Path) != ""
60-
if setupRequired && !isSetup && !isFile {
61-
return requestEvent.Redirect(302, "/admin/setup")
60+
if setupRequired {
61+
// Setup isn't done yet — keep gating. Redirect every
62+
// non-setup page (incl. /admin/auth) back to /admin/setup
63+
// so an abandoned setup can't leave the instance stuck at
64+
// the auth dead-end. Never latch setupCompleted here: a
65+
// visit to /admin/setup itself must not count as "done".
66+
if !isSetup && !isFile {
67+
return requestEvent.Redirect(302, "/admin/setup")
68+
}
6269
} else {
70+
// A real superuser exists — setup is genuinely complete.
71+
// Latch so we stop counting superusers on every request.
6372
setupCompleted = true
6473
}
6574
}

0 commit comments

Comments
 (0)