Identity and user preferences
Identity and user preferences connect the sign-in service to the HTTPSMS user record. Firebase proves who the person is, while the API keeps service data such as the user's time zone, active phone, notification choices, and user API key. The same boundary also controls account removal and invalidates access when a user key changes.
Identity model
Account records
The account is a service record linked to an external Firebase identity. The API creates the record on the first authenticated request when it finds a valid identity but no local record. New records start on the free plan and receive a user API key. The account-created event lets other parts of the system react without making sign-in depend on each downstream action. api/…/user_service.go• L129-163 api/…/gorm_user_repository.go• L209-247
The local user record is the source for service preferences and user-level access. It keeps the Firebase user ID and email together with the user API key, time zone, selected phone, notification flags, and subscription state. Profile editing in this area changes the time zone and active phone; the sign-in identity remains owned by Firebase. api/…/user.go• L73-90 api/…/user_service.go• L178-209
References: api/…/user.go• L73-90 api/…/user_service.go• L129-163 api/…/gorm_user_repository.go• L209-247
Sign-in providers
The web sign-in boundary uses Firebase Authentication. It accepts Google, GitHub, and email sign-in or sign-up flows, then tracks the Firebase user in the web auth store. A signed-in web session waits for Firebase auth state before protected routes continue. web/…/FirebaseAuth.vue• L1-12 web/…/FirebaseAuth.vue• L98-135 web/…/firebase.client.ts• L30-39 web/…/auth.ts• L3-23
The browser sends the Firebase ID token as a bearer token to the API. The API verifies that token and places the resulting identity in the request context. The first request that needs a local user then loads or creates the matching account record. web/…/useApi.ts• L3-34 api/…/bearer_auth_middleware.go• L15-48
References: web/…/FirebaseAuth.vue• L1-12 web/…/FirebaseAuth.vue• L98-135 web/…/firebase.client.ts• L30-39 web/…/auth.ts• L3-23 api/…/bearer_auth_middleware.go• L15-48
Authentication boundaries
Request credentials
The API supports separate credentials for separate trust boundaries. A Firebase bearer token identifies the signed-in person. A user API key gives programmatic access to the user's account. A phone API key is a scoped credential for phone resources and is marked with the pk_ prefix. The user API key is marked with the uk_ prefix when it is created or rotated. api/…/bearer_auth_middleware.go• L15-48 api/…/api_key_auth_middleware.go• L13-37 api/…/phone_api_key_auth_middleware.go• L13-35 api/…/gorm_user_repository.go• L218-230
These credentials do not replace each other. The general API key middleware ignores phone keys, while the phone key middleware resolves phone keys through the phone-key store. A request becomes protected only when the route uses the authenticated middleware after a credential middleware has placed a valid identity in the request context. api/…/api_key_auth_middleware.go• L21-36 api/…/phone_api_key_auth_middleware.go• L21-34 api/…/authenticated_middlesare.go• L20-35 api/…/container.go• L203-205
User routes use this boundary for reading and changing the current account. The notification route and key-rotation route also check the account ID so one authenticated user cannot change another user's settings or key. api/…/container.go• L1693-1697 api/…/user_handler.go• L41-51 api/…/user_handler.go• L248-264
References: api/…/bearer_auth_middleware.go• L15-48 api/…/api_key_auth_middleware.go• L13-37 api/…/phone_api_key_auth_middleware.go• L13-35 api/…/authenticated_middlesare.go• L20-35 api/…/user_handler.go• L41-51
Client credential state
The web API client holds the Firebase bearer token and user API key as separate request values. Firebase auth changes refresh or clear the bearer token. The account store loads the local user after a sign-in change and updates the stored user key after a profile save or key rotation. web/…/useApi.ts• L3-38 web/…/auth.ts• L18-53 web/…/auth.ts• L55-93
This separation lets the dashboard use Firebase for account access while using the user key for API calls. On sign-out or account deletion, the web store clears both local user state and the stored API key. web/…/auth.ts• L28-48 web/…/auth.ts• L76-100
References: web/…/useApi.ts• L3-38 web/…/auth.ts• L18-53 web/…/auth.ts• L55-100
User preference management
Profile preferences
The profile preference update changes the time zone and the active phone used by the web experience. The API normalizes an invalid time zone to UTC and permits the active phone to be cleared. These values are returned with the local user record so the dashboard can keep its view aligned with the API. api/…/user_update_request.go• L12-42 api/…/user_service.go• L178-209 web/…/index.vue• L194-207
The time zone also affects user-facing time formatting and falls back to UTC when it cannot be loaded. The active phone links account preference state to the phone features described in Phone registration and API keys. api/…/user.go• L113-129
References: api/…/user_update_request.go• L12-42 api/…/user_service.go• L178-209 api/…/user.go• L113-129 web/…/index.vue• L194-207
Notification preferences
Notification preferences control four account-level email choices: message status, webhook, phone heartbeat, and newsletter notices. The settings page reads the values from the user record and sends the full set when the user saves the form. api/…/user.go• L85-88 web/…/index.vue• L715-755
The API stores the flags as one user update. Notification work then checks the relevant flag before sending an email, so a saved preference changes later notification behavior rather than only changing the dashboard display. api/…/user_handler.go• L144-175 api/…/user_service.go• L211-240 api/…/user_service.go• L337-364
References: api/…/user.go• L85-88 api/…/user_notification_update_request.go• L7-23 api/…/user_service.go• L211-240 api/…/user_service.go• L337-364 web/…/index.vue• L715-755
Account lifecycle
Account creation
Account creation is lazy. Firebase creates or returns the sign-in identity first; the API creates the local account when an authenticated user calls a user-facing API operation. The local account receives a generated user API key and free-plan state, then emits user.account.created after the record exists. api/…/user_service.go• L129-163 api/…/user_account_created_event.go• L9-16
The web store follows this relationship by loading the API user after the Firebase user changes. This keeps external identity and service account data separate while still making the account feel like one profile in the dashboard. web/…/auth.ts• L18-26
References: api/…/user_service.go• L129-163 api/…/gorm_user_repository.go• L209-247 api/…/user_account_created_event.go• L9-16 web/…/auth.ts• L18-26
Account deletion
Account deletion removes the local user only when the account has no active paid subscription that is still set to renew. The API performs this check before deletion, so an active paid account must pass through subscription cancellation and expiry before the user can remove the account. api/…/user_service.go• L273-306 api/…/user_handler.go• L121-142
After the local record is removed, the API emits user.account.deleted. Subscribers use that event to remove user-owned phones, phone API keys, notifications, webhooks, messages, schedules, integrations, and other related records. The user listener also deletes the matching Firebase auth identity. This makes deletion a cross-system flow rather than a single table operation. api/…/user_account_deleted_event.go• L9-17 api/…/user_listener.go• L155-168 api/…/phone_api_key_listener.go• L83-97 api/…/phone_notification_listener.go• L146-159
The dashboard signs out of Firebase and clears its account, phone, and related local state after the delete request succeeds. The event-driven cleanup can continue across subscribers after the client has returned to the public page. web/…/index.vue• L760-783
This diagram shows the account deletion boundary and its downstream cleanup fan-out.
flowchart LR
A[Authenticated delete request] --> B[Check active paid subscription]
B -->|Allowed| C[Delete local user record]
B -->|Blocked| D[Return deletion error]
C --> E[user.account.deleted event]
E --> F[Delete Firebase identity]
E --> G[Delete user-owned service data]
C --> H[Web client signs out and clears local state]
References: api/…/user_service.go• L273-306 api/…/user_account_deleted_event.go• L9-17 api/…/user_listener.go• L155-168 api/…/phone_api_key_listener.go• L83-97 api/…/phone_notification_listener.go• L146-159 web/…/index.vue• L760-783
User API-key lifecycle
Each local account gets one user API key for programmatic access. Rotation replaces that key with a new value, removes the old key from the lookup cache, and emits user.api-key.rotated. The rotation event sends an email to the account address so the user knows that the old credential is no longer the current key. api/…/gorm_user_repository.go• L57-92 api/…/user_service.go• L242-270 api/…/user_api_key_rotated_event.go• L9-18 api/…/user_listener.go• L70-85
Rotation is a replacement event, not an addition of a second user key. The dashboard updates its stored key only after the API returns the new user record, so later requests use the new credential. web/…/auth.ts• L83-93 web/…/index.vue• L147-168
The user key is different from phone API keys. Phone API keys are separate scoped resources that can cover selected phones and follow the lifecycle in Phone registration and API keys. Subscription effects on account access and deletion are described in Subscription, billing, and entitlements. api/…/phone_api_key.go• L13-23 api/…/phone_api_key_repository.go• L11-38
References: api/…/user.go• L73-78 api/…/gorm_user_repository.go• L57-92 api/…/user_service.go• L242-270 api/…/user_api_key_rotated_event.go• L9-18 api/…/user_listener.go• L70-85 web/…/auth.ts• L83-93
Change checklist
When these files or sections are changed, remember to consider these:
- When the user ID, API-key prefix, or auth-context shape changes, update every credential middleware and the cache invalidation path together.
- When a user preference field changes, keep the user entity, update request, settings payload, response type, and notification consumer aligned.
- When account deletion changes, preserve the
user.account.deletedcontract and review every listener that removes data owned by the user. - When account creation changes, check the point that emits
user.account.createdso downstream setup still happens after the local account exists. - When API-key rotation changes, keep the returned key, old-key cache removal, event email, and browser credential state in the same lifecycle.
- When subscription rules change, review the deletion guard because active renewal state controls whether account deletion can proceed.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A request has no valid Firebase token or user API key | The protected user route returns unauthorized | Credential middleware must set an auth context before the authenticated route guard runs |
| A phone API key is sent to a general user route | The general API-key middleware ignores it | Use the user API key for account access and the phone API-key route boundary for scoped phone access |
| A user rotates the key while a client still sends the old key | Later requests fail because the old key is removed from lookup | Update the client key from the rotation response before making further API calls |
| An active paid subscription still renews | Account deletion is rejected and no deletion event is emitted | Cancel the subscription and wait for the account to reach a non-renewing state |
| A user preference update contains an invalid time zone | The stored time zone becomes UTC | Treat the returned user record as the source of the saved value |
| A deletion subscriber fails after the local user is removed | Some related data or the Firebase identity can remain until event handling succeeds | Monitor the user.account.deleted event and its subscribers as one cleanup flow |
Key files
| File | Why to read it |
|---|---|
| api/…/user.go | Defines the account data and the preference fields that other systems consume. |
| api/…/user_handler.go | Shows the user API surface for account reads, updates, deletion, notifications, and key rotation. |
| api/…/user_service.go | Explains the account lifecycle rules and the events raised for creation, deletion, and key rotation. |
| api/…/gorm_user_repository.go | Shows how local identity records and user-key lookups support the lifecycle. |
| api/…/bearer_auth_middleware.go | Defines the Firebase bearer-token boundary. |
| api/…/api_key_auth_middleware.go | Defines the user API-key boundary. |
| api/…/authenticated_middlesare.go | Defines the final guard for protected routes. |
| api/…/user_listener.go | Connects account events to Firebase deletion and key-rotation email work. |
| api/…/user_account_deleted_event.go | Defines the deletion event shared by cleanup subscribers. |
| web/…/auth.ts | Shows how the dashboard joins Firebase identity, local user state, and client credentials. |
| web/…/index.vue | Shows the user-facing controls for time zone, notifications, key rotation, and account deletion. |
| web/…/useApi.ts | Shows how the browser sends bearer and user API-key credentials. |
| api/…/phone_api_key.go | Distinguishes scoped phone keys from the account-level user key. |
Parent page: Accounts and billing
Related pages: Phone registration and API keys, Subscription, billing, and entitlements, Web dashboard