User Story: Authentication & Session Management
Estado de fase (MASTER-00): POST_MVP — documento de catálogo de producto sujeto a validación; no es alcance aprobado de Gate 0 / PoC / MVP. Gobernanza: MASTER-00.
User Story: Authentication & Session Management
Sección titulada «User Story: Authentication & Session Management»User Story Statement
Sección titulada «User Story Statement»As a registered developer, architect, or engineering manager,
I want to securely log into DocuGraph via email/password or OAuth (GitHub/Google) and maintain an authenticated session across application restarts,
So that my documentation projects, cloud sync settings, and RevenueCat Pro entitlements remain secure and accessible across devices.
Business Rationale & User Impact
Sección titulada «Business Rationale & User Impact»Authentication is the primary security gatekeeper for DocuGraph. It establishes identity for cloud-synchronized projects, secures API key generation for MCP server access, and links the user’s account to their RevenueCat subscription state (US-06). Without secure authentication and persistent sessions, multi-device cloud synchronization and entitlement verification described in VISION-00 cannot function.
User Flow & Interaction Overview
Sección titulada «User Flow & Interaction Overview»- User launches DocuGraph client application (
:docugraph-app). - App checks encrypted local storage for an active, valid JWT refresh token.
- If valid, the session is silently re-authenticated, bypassing the login UI.
- If invalid or missing, the user is presented with the Login UI (
FE-01). - User enters email/password or selects GitHub/Google OAuth login.
- Frontend validates input and dispatches authentication request to backend endpoint
operationId: loginUser. - Backend validates credentials against database (
table: users), returns access token (15-min TTL) and refresh token (30-day TTL). - Client stores tokens in platform secure storage (Android EncryptedSharedPreferences, iOS Keychain, Desktop Encrypted Store) and transitions to Project Dashboard (
FE-02).
Acceptance Criteria (Gherkin Format)
Sección titulada «Acceptance Criteria (Gherkin Format)»Scenario 1: Valid Credentials Login
Sección titulada «Scenario 1: Valid Credentials Login»Given the user is on the Login Screen with valid email "architect@docugraph.io" and correct passwordWhen the user submits the login formThen the client dispatches a POST request to the authentication endpoint (operationId: loginUser)And upon receiving a 200 OK HTTP response with JWT access and refresh tokensThen the tokens are stored in the platform's secure storageAnd the application navigates to the Project Dashboard screen (FE-02) with active session stateScenario 2: Invalid Credentials Handling
Sección titulada «Scenario 2: Invalid Credentials Handling»Given the user enters an unregistered email or incorrect passwordWhen the user submits the login formThen the authentication endpoint (operationId: loginUser) returns a 401 Unauthorized response with error code "INVALID_CREDENTIALS"And an inline error message "Invalid email or password" is displayed on the Login ScreenAnd no session tokens are stored in local secure storageScenario 3: Automatic Session Persistence across Application Restarts
Sección titulada «Scenario 3: Automatic Session Persistence across Application Restarts»Given a previously authenticated user with a valid refresh token stored in platform secure storageWhen the user launches the DocuGraph applicationThen the client automatically issues a silent token refresh requestAnd upon success, the session state is restored without prompting the user for login credentialsAnd the application directly displays the Project Dashboard screen (FE-02)Scenario 4: Secure User Logout
Sección titulada «Scenario 4: Secure User Logout»Given an actively authenticated user session on the Project DashboardWhen the user clicks the "Logout" button in the account settings menuThen the stored access token and refresh token are permanently revoked and wiped from platform secure storageAnd the active session state is cleared from application memoryAnd the application immediately redirects the user back to the Login Screen (FE-01)Functional Requirements & Constraints
Sección titulada «Functional Requirements & Constraints»- Security: Passwords must be hashed server-side using Argon2id or bcrypt with a minimum work factor of 12.
- Token Format: Access tokens must be signed RS256 JWTs containing claims for
user_id,email, andentitlement. - Multiplatform Storage:
- Android:
EncryptedSharedPreferencesvia AndroidX Security library. - iOS: Keychain Services API.
- Desktop JVM: Operating system native key store (Keyring / Credential Manager) with AES-256 encrypted local fallback file.
- Android:
Downstream Atomic Mapping
Sección titulada «Downstream Atomic Mapping»This User Story serves as the direct upstream source of truth for the following downstream specifications:
- Interaction Specification: IX-01_login-flow.md (
IX-01) — Step-by-step user interaction, state transitions, and UI error states. - Backend Specification: BE-01_auth-login.md (
BE-01) — Ktor route handler forPOST /api/v1/auth/login. - API Contract: openapi.yaml — Single source of truth for REST endpoint with
operationId: loginUser. - Frontend Specification: FE-01_login-form.md (
FE-01) — Compose Multiplatform LoginForm composable component. - Database Schema: 01_DATABASE_SCHEMA.md (
table: users) — Relational user accounts table.
Traceability Index
Sección titulada «Traceability Index»- Upstream Dependencies:
- docs/00_BUSINESS_VISION.md (
VISION-00) — Core Business Vision & Security Gatekeeping.
- docs/00_BUSINESS_VISION.md (
- Downstream Direct Linkages (Planned M2/M3):
IX-01_login-flow.md(IX-01)BE-01_auth-login.md(BE-01)FE-01_login-form.md(FE-01)
- Related Stories:
- US-02_create_project.md (
US-02) — Project creation requiring authenticated session. - US-06_revenuecat_pro.md (
US-06) — Entitlement verification bound to user identity.
- US-02_create_project.md (