Documentation
¶
Overview ¶
Package api implements the server-side user management API for the simple-frontend-stack application. It handles initial setup for user accounts via API endpoints and ensures the first user creation process is performed safely and atomically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterUserAPI ¶
func RegisterUserAPI(app *pocketbase.PocketBase, cfg configuration.AppConfig)
RegisterUserAPI registers the user management API endpoints with the PocketBase server. It attaches three HTTP routes: - GET /api/user/exists : Determines if any user accounts beyond the default exist. - POST /api/user/create-admin-user : Creates the first normal user and matching superuser when none exist. - GET /api/user/is-authenticated : Checks if the current request is authenticated and if admin creation is allowed.
GET /api/user/exists responses:
200 OK - {"exists":true} if at least one user exists or the superuser state is non-default.
{"exists":false} if no users and only the initial default superuser remain.
500 Error - On database count or fetch failures.
POST /api/user/create-admin-user expected form parameters:
email (string) Required. Valid email for new accounts. password (string) Required. Minimum 10 characters. passwordConfirm (string) Required. Must match 'password'.
Responses:
200 OK - {"success":true} on successful account creation.
400 Bad Request - Missing/invalid parameters or password mismatch/length issues.
409 Conflict - When users already exist or unexpected superuser state.
500 Error - On database operation failures or transaction rollbacks.
GET /api/user/is-authenticated responses:
200 OK - {"isAuthenticated":bool, "canCreateAdmin":bool}
500 Error - On database count or fetch failures (during canCreateAdmin check).
Types ¶
This section is empty.