Requirement EPIC
- Epic
- MVP2 · E8 · Passwordless identity, built by hand
- Goal
- replace Cognito with our own provider. Libraries allowed:
@node-rs/argon2, jose, @simplewebauthn/*, Node crypto, Resend. No auth vendors or auth frameworks. - Stories in this module
- 12
IDENTITY-V2-E8-01 Identity schema and session service
Size MIdentity
- AC1New tables:
auth_identities (user_id, type email|passkey, identifier), sessions (id, user_id, token_hash, created_at, last_seen_at, expires_at, absolute_expires_at, ip_hash, user_agent), login_tokens (id, email, token_hash, purpose, expires_at, used_at), passkeys (credential_id, user_id, public_key, counter, transports, name, created_at, last_used_at) and recovery_codes (user_id, code_hash, used_at). - AC2Session tokens are 32 random bytes from
crypto.randomBytes; only the SHA-256 hash is stored. The cookie is __Host-session, HttpOnly, Secure, SameSite=Lax. - AC3Sessions use a 7-day sliding expiry, capped at 30 days, and both are enforced on the server.
- AC4The OIDC client from MVP1 is replaced behind the same
getCurrentUser() interface, with no changes to page code.
IDENTITY-V2-E8-02 Magic link sign-in and sign-up
Size MIdentity
As Priya, I want to sign in by clicking a link in my email.
- AC1Given I enter an email, then the response is always "Check your email", whether or not an account exists, and takes about the same time either way.
- AC2A token of 32 random bytes is created and only its hash stored, with a 15-minute expiry and single use. The link goes to
/auth/confirm?token=…. - AC3The confirm page needs a deliberate "Sign in" click (POST), so email link scanners can't use the token. The token is checked (hash match, not expired, not used), marked used, and a session is created.
- AC4An unknown email creates a new user on first confirmation (sign-up and sign-in are one flow).
- AC5Rate limits: 5 requests per email per hour and 20 per IP per hour, after which the user sees a generic message.
auth.magic_link_requested and auth.signin are audited.
IDENTITY-V2-E8-03 Email one-time code fallback
Size SIdentity
- AC1The same email also has a 6-digit code, valid 10 minutes, stored as a hash.
- AC2A code allows at most 5 tries, then it's invalidated. The comparison is constant-time.
- AC3A code-entry form on the sign-in page supports paste and the phone's one-time-code autofill.
IDENTITY-V2-E8-04 Passkeys: register and sign in
Size LIdentity
- AC1After sign-in, I'm offered "Add a passkey". Registration uses
@simplewebauthn/server with the relying party ID 01scale.com and requires user verification. - AC2"Sign in with passkey" works without typing an email, using browser autofill where supported.
- AC3The signature counter and backup flags are checked and stored. A replayed or invalid assertion is rejected and audited.
- AC4I can name, list and remove passkeys on
/account/security. Removing one requires re-authentication within the last 5 minutes. - AC5Tested on iOS Safari, Android Chrome and desktop Chrome, with results recorded in the PR.
IDENTITY-V2-E8-05 Recovery codes
Size SIdentity
- AC1When the first passkey is registered, 10 single-use recovery codes are shown once and stored hashed with argon2.
- AC2A recovery code signs me in, is marked used, and prompts me to add a new passkey.
- AC3I can regenerate codes, which invalidates the old set; this requires re-authentication.
IDENTITY-V2-E8-06 Session management page
Size SIdentity
- AC1
/account/security lists active sessions with device, approximate location from IP if available, and last active time, with the current one marked. - AC2I can revoke any session or "Sign out everywhere else". A revoked session is rejected on its next request.
IDENTITY-V2-E8-07 Re-authentication for sensitive actions
Size SIdentity
- AC1Changing email, removing a passkey or payment method, deleting the account and regenerating recovery codes all require proof (passkey or email code) within the last 5 minutes.
- AC2Changing email sends confirmation to the new address and a notice to the old one.
IDENTITY-V2-E8-08 Cognito migration and shutdown
Size MIdentity
- AC1Given an MVP1 user signs in with a magic link to their verified email, then they're matched to their existing
users row by email and keep all their documents and orders. - AC2A migration report shows migrated vs not-yet-migrated users.
- AC3After 30 days, Cognito sign-in is turned off, its environment variables are removed, and a decision record
docs/services/v2/DECISIONS.md explains the build-vs-buy and migration choices.
IDENTITY-V2-E8-09 Auth security hardening
Size MIdentity and service template
- AC1CSRF protection on all state-changing routes (SameSite plus an origin check).
- AC2Every auth event is audited: requested, succeeded, failed, locked, passkey added/removed, session revoked.
- AC3An OWASP ASVS v4 chapter 2 and 3 checklist (authentication, sessions) is completed in
docs/security/asvs-auth.md, with each item marked pass, fail or n/a.
IDENTITY-V2-E8-10 Account security on our own screens
Size SIdentity
Decided by Nikhil on 17 Nov 2026 (issue #26): in MVP1, "Change password" uses Cognito's hosted forgot-password page; our own screens come with hand-built identity. As a user, I want to manage how I sign in on 01scale's own account page, without being sent to another site.
- AC1
/account/security replaces MVP1's "Change password" button. MVP2 sign-in is passwordless, so there is no password to change: the page lists my sign-in methods (my email for magic links and codes, and my passkeys), and I can add a passkey, remove one (with re-authentication, IDENTITY-V2-E8-07) or change my email. - AC2No step sends me to an outside page. Every action is an Identity endpoint with its UI component in
packages/ui-identity. - AC3An MVP1 user who signed in with a password and has not yet set up a passkey sees a prompt to add one.
IDENTITY-V2-E8-11 Deactivate first, delete after 30 days
Size SIdentity only: other services need no change, because a deactivated user cannot sign in and their data is reachable only by them.
Decided by Nikhil on 20 Nov 2026 (PR #70): MVP1 deletes an account at once; MVP2 adds a 30-day window to undo a deletion. As a user, I want a deleted account to stay recoverable for 30 days, so a mistake or a change of mind does not lose my work, while my data is still erased for good afterwards.
- AC1"Delete account" deactivates the account at once: I am signed out everywhere, my sessions, API keys and agents stop working, and no one can reach my data. I see the date it will be deleted for good.
- AC2Signing in within 30 days offers **Restore account**, which brings everything back as it was. After restoring, nothing has been deleted.
- AC3After 30 days, a daily job deletes the account for good through the existing
identity.user.deleted event, so every service deletes or anonymizes its own data exactly as in MVP1. "Delete now" skips the wait for anyone who asks. - AC4While deactivated, the account receives no emails, and
GET /api/identity/v1/users/{userId} answers 404, so no service writes to it. - AC5Deactivation, restore and the final deletion are each audited. The consent line and the account page say that deletion completes 30 days after the request.
IDENTITY-V2-E8-12 Rotate service client secrets without downtime
Size SIdentity
Decided by Nikhil on 20 Nov 2026 (PR #73): parked for MVP2. In MVP1 a client secret changes only with a database migration and a deployment. As the owner, I want to change a service's or app's client secret without any moment where its calls fail, so a leaked or old secret can be replaced at once and routinely.
- AC1Each client can hold two active secrets at the same time. Identity accepts either while both are active.
- AC2Rotating is three steps with no downtime: add a new secret; set it in the client's environment and redeploy; retire the old secret. Retiring it takes effect on the next sign-in; tokens already issued last at most 5 minutes.
- AC3A secret can also be retired at once in an emergency, for example after a leak, even if the client then fails until it has the new one.
- AC4The admin page shows, per client, when each secret was created and last used, so an unused old secret is easy to spot. Each secret is shown once at creation and stored only as a hash.
- AC5Adding and retiring secrets are admin and session-only actions, never available to API keys or agents, and are audited.
All Identity V2 epics and stories on GitHub →