Current deployed baseline: v50.1
Next planned package: v51

Current baseline: v48
Next planned package: v49

CURRENT CANONICAL BASELINE
Version: v39
Status: documentation expansion package
Next planned package: v40

# Auth and Identity Plan

## Current phase note
- v39.1 formalizes authentication, identity, verification, password recovery, and email-based two-factor authentication as first-class architecture streams.

## Purpose
This document defines the planned identity architecture for Dispatch Spot so authentication, account recovery, verification, and future multi-factor authentication can scale cleanly across workspaces, roles, security policies, and future mobile clients.

## Identity Principles
- Authentication logic must remain service-driven and API-first.
- Security-critical tokens must be hashed at rest.
- Identity events must be auditable.
- Workspace access and user identity are related but not the same thing.
- MFA architecture must support email 2FA now and stronger app-based MFA later.

## Core Identity Responsibilities
- Sign up
- Sign in
- Session lifecycle
- Email verification
- Password reset
- Email-based two-factor authentication
- Invite acceptance
- Role-aware workspace access
- Login security alerts
- Session revocation

## Planned User and Access States
- PENDING_EMAIL_VERIFICATION
- ACTIVE
- LOCKED
- DEACTIVATED
- INVITED
- PASSWORD_RESET_REQUIRED

## Email Verification Plan
### Purpose
Confirm ownership of the user email address at signup and whenever the email address changes.

### Flow
1. User signs up or is invited.
2. Account is created in a pending verification state.
3. Verification token is generated and stored hashed.
4. Verification email is sent through the notification service.
5. User clicks verification link.
6. Token is validated and marked used.
7. Email is marked verified.
8. Security audit event is written.

### Rules
- Verification tokens expire after 24 hours.
- Resend is allowed with cooldown and abuse limits.
- Issuing a new token invalidates prior unused verification tokens.
- Invite-based access should not become fully active until verification completes.

## Password Recovery Plan
### Purpose
Provide secure self-service recovery without exposing whether an account exists.

### Flow
1. User requests password reset.
2. Application always returns a neutral response.
3. If account exists, a reset token is generated and stored hashed.
4. Password reset email is sent through the notification service.
5. User opens reset link and sets new password.
6. Token is invalidated.
7. Existing sessions may be revoked based on security policy.
8. Confirmation email is sent after password change.

### Rules
- Reset tokens expire within 30 to 60 minutes.
- Tokens are single-use only.
- Password changes must be logged.
- Abuse limits must apply by IP and account fingerprint.

## Email Two-Factor Authentication Plan
### Purpose
Add a low-friction second factor before SMS and authenticator app methods are introduced.

### Initial Scope
- Super Admin accounts
- Workspace Admin accounts
- New device sign-ins
- Suspicious login attempts
- Sensitive security actions

### Flow
1. User enters valid password.
2. Policy engine determines whether challenge is required.
3. A short-lived one-time code is generated.
4. Code is sent through the notification service.
5. User submits code.
6. Code is validated.
7. Login succeeds and audit event is written.

### Rules
- 6-digit code
- 10-minute expiry
- 5 maximum attempts
- resend cooldown
- optional remember-device support for low-risk devices

## Future MFA Direction
The architecture should later support:
- TOTP / authenticator apps
- backup codes
- SMS as an optional factor
- risk-based challenge escalation

## Token and Session Storage Direction
Planned identity tables or equivalents should preserve support for:
- email verification tokens
- password reset tokens
- MFA challenge tokens
- session records
- device trust records
- security event records

## Security Event Logging
The system should audit:
- sign in success and failure
- email verification sent and completed
- password reset requested and completed
- MFA challenge issued and verified
- session revoked
- suspicious login detected
- role change affecting elevated access

## Build Rule Going Forward
All security-sensitive identity actions must route through a dedicated auth or notification service and must never rely on page-only logic.


- v49: Added auth token consumption flows for email verification and password reset, including token validation, single-use handling, expiry enforcement, and password reset completion.
