SR-027 — Mobile Login & Signup: System Requirements

By Engineering Team•October 10, 2026•6 min read
Metadata Details
System Name Mobile Login & Signup — user-secure-engine’s phone-OTP flows + ui-application’s pre_auth feature
Document ID SR-2026-AUTH-001
Author Engineering Team
Status Implemented (gaps noted inline)

Traces back to BRD-026 — Mobile Login & Signup: Phone-Based Identity and Legal Acceptance.

This spec covers ui-application’s unauthenticated pre_auth feature (splash, phone signup, phone login, OTP verification, policy viewer) and the backend flows it drives: user-secure-engine’s four unauthenticated /auth/otp/* endpoints, Firebase Identity Toolkit account lookup/creation and custom-token minting, the account-initialization saga that provisions the users row and PII attributes, and the gateway’s App-Check-only enforcement for routes that have no bearer token yet.

Functional Requirements

Phone-OTP Login (user-secure-engine)

  • FR-01 (Send login OTP, existence precondition): POST /auth/otp/login/send looks up the phone number against Firebase Identity Toolkit (FirebaseServiceTrait::lookup_user_by_phone) before sending anything; if no account exists, the request is rejected (404) and no OTP is sent. On a match, a 6-digit code is generated and sent under OtpPurpose::PhoneLogin, hashed and rate-limited by the existing OTP mechanism (see NFR-01/NFR-02).
  • FR-02 (Verify login OTP, no Firebase writes): POST /auth/otp/login/verify verifies the submitted code against the same purpose/hash bucket. On success, it re-looks-up the phone number for its Firebase uid and mints a Firebase custom token (FirebaseServiceTrait::mint_custom_token) — no Identity Toolkit write of any kind happens on login, since the account already exists. On failure, the request is rejected with an invalid-or-expired-code error.

Phone-OTP Signup (user-secure-engine)

  • FR-03 (Send signup OTP, conflict precondition): POST /auth/otp/signup/send performs the same lookup as FR-01 but with inverted polarity — if an account already exists for the phone number, the request is rejected (409) and no OTP is sent. On no match, a code is sent under the distinct OtpPurpose::PhoneSignup, so signup and login never share a hash/rate-limit bucket for the same phone number.
  • FR-04 (Verify signup OTP, consent gate, account creation): POST /auth/otp/signup/verify first rejects the request outright if terms_accepted is false — no OTP verification is even attempted without consent. On a successful code verification, it creates the Firebase account via create_user_by_phone (not a second lookup — Identity Toolkit itself is the atomic uniqueness backstop against a concurrent duplicate signup, mapped to a conflict error), stamps role/terms_accepted/terms_version/privacy_version as Firebase custom claims, and mints a custom token.
  • FR-05 (Three-tab policy viewer): A shopper can read the Terms & Conditions, Privacy Policy, and Returns & Exchange policy from a single viewer with three tabs, reachable both from the signup screen (before accepting) and independently. The Returns & Exchange tab has no acceptance action — it is read-only by design, not an omission.
  • FR-06 (Single consent action, two tracked document versions): Signup presents exactly one consent checkbox covering both the Terms & Conditions and the Privacy Policy — there is no second, separate Privacy checkbox. Despite the single checkbox, the two documents’ version identifiers (terms_version, privacy_version) are captured and recorded independently, so a later version change to either document is distinguishable from the other.

Automatic Account Initialization

  • FR-07 (Dual-path, idempotent account provisioning): The moment a signup OTP verification succeeds, the shopper’s users row and PII attributes (full name, email, phone number) are provisioned automatically, with no manual step by the shopper or support staff, through two deliberately redundant paths: a synchronous call made directly inside the OTP-verify request itself, and an asynchronous Firebase onCreate background trigger that calls the same initialization operation after signInWithCustomToken fires. Both paths call the same idempotent operation (an existence check followed by an atomic insert-if-absent), so whichever path runs second becomes a no-op rather than a duplicate or a conflict.
  • FR-08 (Phone-only verification status): Because this flow captures no email address at signup, a shopper’s account reaches “active” status based on phone verification alone — an unset email channel is treated as vacuously verified rather than blocking activation indefinitely.

Gateway Enforcement for Pre-Auth Routes

  • FR-09 (App-Check-only enforcement, no bearer token): The four unauthenticated /auth/otp/* routes are verified for Firebase App Check at the gateway before reaching the service, through a dedicated internal check that validates only X-Firebase-AppCheck — since no Authorization header exists yet for a request that hasn’t logged in. Every other route in the system still requires both App Check and a bearer token.

First Launch

  • FR-10 (Splash screen before identity choice): A shopper opening the app is shown a brief first-launch screen while the app prepares itself, before being offered the choice to sign up or log in.

Non-Functional Requirements

  • NFR-01 (OTP rate limiting): Every OTP send/resend is subject to a minimum cooldown between requests and a rolling-hour cap per contact, enforced atomically against the same record the code itself is stored in — a burst of requests against one phone number cannot bypass the limit by arriving concurrently.
  • NFR-02 (OTP codes bound to full request context, never logged in production): An OTP’s stored hash is computed over the full request context (tenant, purpose, channel, contact), not the code alone, so a hash can only ever match the exact request it was generated for. The generated plaintext code itself is never emitted at the production log level — only at a debug level that is structurally absent once logging is configured for production.
  • NFR-03 (No password credential, ever): No password field, hash, or reset path exists anywhere in this flow — phone-OTP is the sole credential mechanism for both signup and login, with no fallback.
  • NFR-04 (Mandatory tenant scoping on unauthenticated routes): Because the four /auth/otp/* routes have no bearer token to source tenant scope from, every request to them must carry an explicit tenant identifier header, rejected outright if absent — tenant scoping is never inferred or defaulted on these routes. (Gap — the Firebase onCreate trigger side of FR-07’s saga currently sources its tenant identifier from a single hardcoded environment placeholder rather than per-request data, tracked as technical debt, see TD-00021.)
  • NFR-05 (Policy version traceability): A recorded Terms/Privacy acceptance always carries the specific version identifier in effect at the moment of acceptance, so a later policy update is always distinguishable from a shopper’s prior acceptance.
  • NFR-06 (Saga compensation on partial failure): If the account-provisioning saga’s PII write succeeds but the identity-row insert fails, the already-written PII is rolled back via a compensating delete, rather than leaving an orphaned PII record with no corresponding account.
  • NFR-07 (Resend attempt cap): A shopper may request a code resend only a bounded number of times per verification attempt before being required to restart the flow, so a stuck verification screen cannot retry indefinitely.