authentication
12 requirements and 37 scenarios in openspec/specs/authentication/spec.md. A scenario’s test is test('<scenario>') inside describe('<requirement>'), in Vitest or Playwright.
Sign in with an emailed code
Section titled “Sign in with an emailed code”Playwright: e2e/sign-in.spec.ts
| Scenario | Tests |
|---|---|
| A new address creates an account and signs in | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/sign-in.spec.ts |
| An existing user signs in to the same account | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/sign-in.spec.ts |
| The address is matched without regard to case | Vitest src/features/authentication/sign-in.server.test.ts |
| The code email is in the user’s language | Vitest src/features/authentication/sign-in.server.test.ts |
Rejecting wrong and expired codes
Section titled “Rejecting wrong and expired codes”Playwright: e2e/sign-in.spec.ts
| Scenario | Tests |
|---|---|
| A wrong code shows an error | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/sign-in.spec.ts |
| An expired code is rejected | Vitest src/features/authentication/sign-in.server.test.ts |
| Five wrong attempts use up the code | Vitest src/features/authentication/sign-in.server.test.ts |
| A used code does not work twice | Vitest src/features/authentication/sign-in.server.test.ts |
| A new code replaces the previous one | Vitest src/features/authentication/sign-in.server.test.ts |
Requesting a new code
Section titled “Requesting a new code”Playwright: e2e/sign-in.spec.ts
| Scenario | Tests |
|---|---|
| A new code can be requested after 30 seconds | Vitest src/features/authentication/SignInPage.test.tsxPlaywright e2e/sign-in.spec.ts |
| An expired code offers a new one at once | Vitest src/features/authentication/SignInPage.test.tsx |
| Changing the address goes back to the email step | Vitest src/features/authentication/SignInPage.test.tsxPlaywright e2e/sign-in.spec.ts |
Choosing the language before sign-in
Section titled “Choosing the language before sign-in”Playwright: e2e/sign-in.spec.ts
| Scenario | Tests |
|---|---|
| Choosing Swedish on the sign-in page | Playwright e2e/sign-in.spec.ts |
| Choosing a language changes an existing account’s language | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/sign-in.spec.ts |
| A cookie left on the device does not change the account’s language | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/sign-in.spec.ts |
Limiting code requests
Section titled “Limiting code requests”No Playwright test: the limits are counters shared across the whole test run, so browser tests reaching them would make other tests fail; Workers tests cover them against D1.
| Scenario | Tests |
|---|---|
| A fourth request from one IP address within a minute is refused | Vitest src/features/authentication/sign-in.server.test.ts |
| A sixth code for one address within an hour is refused | Vitest src/features/authentication/sign-in.server.test.ts |
| The address limit frees up after an hour | Vitest src/features/authentication/sign-in.server.test.ts |
Telling the user when the code email cannot be sent
Section titled “Telling the user when the code email cannot be sent”No Playwright test: the end-to-end build sends through the capture transport, which cannot be made to fail on demand; Workers tests drive the failures through a failing sender.
| Scenario | Tests |
|---|---|
| The email quota is used up | Vitest src/features/authentication/sign-in.server.test.ts |
| Sending is briefly limited | Vitest src/features/authentication/sign-in.server.test.ts |
| Sending fails for another reason | Vitest src/features/authentication/sign-in.server.test.ts |
Pages for signed-in users only
Section titled “Pages for signed-in users only”Playwright: e2e/session.spec.ts
| Scenario | Tests |
|---|---|
| A visitor is sent to sign in | Playwright e2e/session.spec.ts |
| A signed-in user skips the sign-in page | Playwright e2e/session.spec.ts |
Signing out
Section titled “Signing out”Playwright: e2e/session.spec.ts
| Scenario | Tests |
|---|---|
| Signing out ends the session | Playwright e2e/session.spec.ts |
| A signed-out session cookie no longer works | Vitest src/features/authentication/sign-in.server.test.ts |
Staying signed in
Section titled “Staying signed in”No Playwright test: the scenarios depend on the passage of days; Workers tests set the session’s expiry directly.
| Scenario | Tests |
|---|---|
| A session expires after 30 days without use | Vitest src/features/authentication/sign-in.server.test.ts |
| Using the app extends the session | Vitest src/features/authentication/sign-in.server.test.ts |
The user’s language is stored on the account
Section titled “The user’s language is stored on the account”Playwright: e2e/session.spec.ts
| Scenario | Tests |
|---|---|
| A new account keeps the sign-in language | Vitest src/features/authentication/sign-in.server.test.ts |
| Signing in on another device uses the stored language | Vitest src/features/authentication/sign-in.server.test.tsPlaywright e2e/session.spec.ts |
| A changed language cookie is put back | Playwright e2e/session.spec.ts |
Test inbox for end-to-end tests
Section titled “Test inbox for end-to-end tests”No Playwright test: it is test infrastructure; every Playwright sign-in uses it, and Vitest checks that it is closed outside capture and that production sends through Resend.
| Scenario | Tests |
|---|---|
| The test inbox returns captured emails | Vitest src/features/authentication/sign-in.server.test.ts |
| The test inbox is closed with a real transport | Vitest src/features/authentication/sign-in.server.test.ts |
| Production does not capture emails | Vitest src/wrangler-config.test.ts |
Asking for a display name
Section titled “Asking for a display name”Playwright: e2e/welcome.spec.ts
| Scenario | Tests |
|---|---|
| A user without a name is asked for one | Playwright e2e/welcome.spec.ts |
| An empty name is not saved | Playwright e2e/welcome.spec.ts |
| A name with an address or a link is not saved | Vitest src/features/authentication/schemas.test.ts |
| A user with a name is not asked again | Playwright e2e/welcome.spec.ts |