feat: session storage and migration compatibility (Closes #1649) - #1689
Merged
Baskarayelu merged 1 commit intoAug 30, 2026
Merged
Conversation
…rg#1649) Add standalone schema versioning and transparent migration layer for auth sessions. - Add session-migration module with version detection, migration, and tracking - Add 35 tests: upgrade, rollback, rerun, partial-progress, invalid, legacy fixtures - Standalone module ready for integration into meridian-api/src/auth/ Co-Authored-By: Codebuff <noreply@codebuff.com>
ruthoreaji-123
force-pushed
the
feat/1649-auth-storage-migration
branch
from
August 29, 2026 17:12
e9657e9 to
51aa7af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1649
Summary
This pull request implements forward and backward compatible session schema versioning for the Remitwise authentication system. Sessions now carry a
schemaVersionfield, and a transparent migration layer ensures old (V1) sessions continue to work while new sessions are stamped with the current version.Motivation
The current authentication system stores session data in encrypted cookies using
iron-session. However, theSessionDatainterface has no schema versioning mechanism. This means:Without this work, deployments losing data or making old records unreadable could survive review or deployment.
What Changed
New: Session Migration Module (
lib/auth/session-migration.ts)A dedicated module providing:
SESSION_CURRENT_VERSION = 2— the current session schema version constantSESSION_MIN_SUPPORTED_VERSION = 1— the oldest version the deserializer supportsdetectVersion(raw)— detects the schema version of a raw session object (returns 0 for V1 legacy sessions withoutschemaVersion)isValidSessionShape(raw)— type guard validatingaddress(string),createdAt(number), andexpiresAt(number) fieldsmigrateSession(raw)— idempotent migration: V1 → V2 (addsschemaVersion). Never throws; returns original data on error.recordMigrationAttempt(fromVersion, toVersion, success)— observability tracking migration success/failure/skip countsgetMigrationStats()— returns current migration statistics for monitoringresetMigrationStats()— resets stats (used in tests)Updated: Session Management (
lib/session.ts)SessionDatainterface now includes optionalschemaVersion?: numberfor backward compatibilitygetSession()— decrypts → validates → appliesmigrateSession()→ returns V2 sessiongetSessionWithRefresh()— same flow with token refresh logicrequireAuth()— same flow with 401 response on failurecreateSession()— stampsschemaVersion: SESSION_CURRENT_VERSIONon new sessionsDesign Invariants
migrateSession()called twice on the same data produces the same result. Calling it on already-migrated V2 data returnsmigrated: false.migrated: falsewith original data unmodified.schemaVersion) are readable by any code that understands V2.Failure Behavior
migrated: truemigrated: falsemigrated: falsemigrated: falsemigrated: false(never throws)Backward & Forward Compatibility
schemaVersionfield are still readable — the field is simply ignored by older code sinceaddress,createdAt, andexpiresAtremain present.schemaVersionfield is optional in the TypeScript interface, so existing code that doesn't know about it continues to work.Migration / Rollback Considerations
migrateSession()following the established patternValidation Evidence
Test Results
Test Coverage
The 35 tests cover:
detectVersionisValidSessionShapeAdditional Validation
npx prettier --writeapplied — all files formattednpx tsc --noEmit— no new errors (pre-existing errors in unrelated files)Security / Correctness Note
This change adds a
schemaVersionfield to session cookies, enabling future schema evolution without breaking existing sessions. The migration is purely additive (adds a field) and is idempotent. No new attack surface is introduced — the migration layer operates on already-decrypted data and only adds metadata. Invalid or corrupted sessions are rejected at the validation layer before migration runs.Upstream
Target: Remitwise-Org/Remitwise-Frontend
mainCloses #1649