Don't show the create-account form once AuthGuard already has an account
Lint / Lint (push) Successful in 49s
Tests / Go backend (push) Successful in 46s
Tests / Dashboard checks (push) Successful in 1m0s
Docker / Docker Build & Push (push) Successful in 4m11s

Accounts are centralized in AuthGuard now, so this project's own "first
launch, create the admin account" flow needs to know whether AuthGuard
already has one - not just whether *this* project's local setup has been
claimed. A fresh instance pointed at an AuthGuard that already has a
superadmin (created via AuthGuard's own web UI, or a sibling project's
setup) was incorrectly still showing its own create-account form.

Both the status check and the setup/registration handler now also consult
AuthGuard's GET /api/setup-status (via the vendored authclient's new
SetupStatus method) before deciding: if AuthGuard already has an account,
show the login screen instead, and reject a setup attempt that reaches the
handler anyway (e.g. a stale page) the same way an already-claimed local
setup is rejected.

Also updates the vendored shared/backend/authclient to add PublicUser's
totp_enabled field (AuthGuard has reported it for a while; the client
just hadn't picked it up).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-02 10:32:55 +02:00
1 parent 4e39b5ac67
commit 51e0a4217b
3 files changed
+124 -17

No files matched your search

+26 -7
View File
@@ -218,14 +218,16 @@ func (c *Client) tokenFromRequest(r *http.Request) string {
// cookie the same way Middleware does (see tokenFromRequest).
// PublicUser is the account payload register/login/me return: {"id",
// "username", "email", "role"}. It is deliberately distinct from the slimmer
// User type Validate/Middleware use (which mirrors GET
// /api/session/validate's {"user_id", "username", "role"} instead).
// "username", "email", "role", "totp_enabled"}. It is deliberately distinct
// from the slimmer User type Validate/Middleware use (which mirrors GET
// /api/session/validate's {"user_id", "username", "role"} instead, and does
// not carry TOTP status at all).
type PublicUser struct {
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Role string `json:"role"`
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Role string `json:"role"`
TOTPEnabled bool `json:"totp_enabled"`
}
// ManagedUser is one row of GET /api/admin/users, and the payload returned
@@ -359,6 +361,23 @@ func (c *Client) call(ctx context.Context, method, path, token string, body, out
return resp, nil
}
// SetupStatus calls GET /api/setup-status, an unauthenticated endpoint that
// reports whether AuthServer has any account at all. Accounts are
// centralized in AuthServer, so a caller with its own "first launch, create
// the initial admin" flow should consult this first: when it reports false,
// some account already exists (possibly created by a different project, or
// directly against AuthServer), and the caller should show its ordinary
// login screen instead of its own account-creation form.
func (c *Client) SetupStatus(ctx context.Context) (bool, error) {
var out struct {
SetupRequired bool `json:"setup_required"`
}
if _, err := c.call(ctx, http.MethodGet, "/api/setup-status", "", nil, &out); err != nil {
return false, err
}
return out.SetupRequired, nil
}
// Register calls POST /api/register, creating a new AuthServer account and
// starting a session for it.
func (c *Client) Register(ctx context.Context, username, email, password string) (*SessionResult, error) {