2.2 KiB
2.2 KiB
Task 01: Persistent OAuth-state & Session Store
Assigned to: Antigravity (Implementation Orchestrator)
Priority: HIGH
Date: 2026-08-21
Base SHA: b2888950cdd2d948c15acf0004a0cdc91eeb70e6
Scope
- Add
OAuthTransactionandSessionmodels toprisma/schema.prisma.OAuthTransaction:id(@id @default(cuid())),state(@unique),codeVerifier,redirectTarget(optional string),createdAt,expiresAt. Index onexpiresAt.Session:id(@id @default(cuid())),sessionId(@unique),userId(FK toUser),userrelation,createdAt,expiresAt. Index onexpiresAt,userId.
- Generate migration SQL under
prisma/migrations/(timestamped migration folder). - Implement
PrismaOAuthTransactionStoreinsrc/lib/auth/oauth-state.tsimplementingIOAuthTransactionStore.- Atomic single-use
consumeTransaction(atomic delete/find). - TTL check after atomic consumption.
- Atomic single-use
- Implement
PrismaSessionStoreinsrc/lib/auth/session.tsimplementingISessionStore.createSession: persists session withexpiresAt = Date.now() + ttlMs.getSession: finds non-expired session bysessionId, loads user, returnsSessionUserornull.destroySession: deletes session bysessionId.clear: deletes all sessions.
- Create store factory / default selector based on
STORAGE_DRIVER&NODE_ENV:createOAuthTransactionStore()&createSessionStore():STORAGE_DRIVER === 'memory' || process.env.NODE_ENV === 'test'-> Memory, otherwise Prisma.- Remove fatal on
MULTI_INSTANCEfor Prisma stores; keep fatal guard for Memory stores.
- Tests in
tests/persistent-auth-stores.test.ts:- Concurrent
consumeTransactionon single state: exactly 1 success, N-1 fail / 401. - Multi-instance state consumption (two store instances sharing storage).
- TTL expiry checks for both OAuth transaction and Session.
destroySessionand session revival prevention.
- Concurrent
- Run verification gate:
npm ci,npx prisma generate,npm test,npm run lint,npm run build,npx tsc --noEmit. - Write final report to
agents/antigravity/done/TASK-2026-08-21-01-persistent-auth-stores.md.