Skip to content

Conversation

@tylerjroach
Copy link
Member

  • PR title and description conform to Pull Request guidelines.

Issue #, if available:
#3159

Description of changes:

Fix: Resolve logout issue caused by JWT token serialization breaking change

Problem

Commit 047483866231622a362f736350f600072affad86 introduced type-safe JWT token classes but inadvertently created a breaking change in the serialized data structure. This caused existing users to be automatically logged out when updating to the new version.

Root Cause: The new token classes (IdToken, AccessToken, RefreshToken) were serialized as nested objects instead of flat strings, causing deserialization failures for existing stored tokens.

Impact

  • Existing users: Tokens stored as "idToken": "eyJhbGc..." could not be deserialized
  • Updated users: Some users got tokens stored as "idToken": {"tokenValue": "eyJhbGc..."}
  • Result: Automatic logout on app launch after update

Solution

Added backward-compatible serialization that:

  1. Maintains flat format: Tokens serialize as raw strings ("idToken": "eyJhbGc...")
  2. Handles all formats: Deserializes both flat strings and nested objects seamlessly
  3. Auto-migration: Nested tokens are automatically flattened on next save
  4. Type safety: Preserves all benefits of the new JWT parsing classes

Changes Made

Core Implementation

  • Custom serializers: Added IdTokenAsStringSerializer, AccessTokenAsStringSerializer, RefreshTokenAsStringSerializer
  • Format detection: extractTokenValue() helper detects and handles both formats

Comprehensive Testing

  • Flat format compatibility: Existing tokens deserialize correctly
  • Nested format support: Problematic tokens from broken version work
  • Auto-migration: Nested tokens convert to flat format on serialization
  • Format consistency: All paths produce identical results

Backward Compatibility Matrix

User Type Stored Format Result
Existing users "idToken": "eyJhbGc..." ✅ Works seamlessly
Updated users "idToken": {"tokenValue": "eyJhbGc..."} ✅ Auto-migrated to flat
New users "idToken": "eyJhbGc..." ✅ Clean flat format

Files Changed

  • Tokens.kt: Added backward-compatible serializers
  • TokensTest.kt: Comprehensive serialization compatibility tests

Testing

  • ✅ All existing tests pass
  • ✅ New tests cover flat format, nested format, and migration scenarios
  • ✅ JWT parsing functionality preserved across all formats

This fix ensures no users experience logout issues while maintaining all the benefits of the type-safe JWT implementation.

How did you test these changes?
(Please add a line here how the changes were tested)

Documentation update required?

  • No
  • Yes (Please include a PR link for the documentation update)

General Checklist

  • Added Unit Tests
  • Added Integration Tests
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Ensure commit message has the appropriate scope (e.g fix(storage): message, feat(auth): message, chore(all): message)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@tylerjroach tylerjroach requested a review from a team as a code owner November 17, 2025 16:00
@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.78%. Comparing base (e54f435) to head (b431c24).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3162      +/-   ##
==========================================
+ Coverage   54.77%   54.78%   +0.01%     
==========================================
  Files        1047     1047              
  Lines       31251    31267      +16     
  Branches     4673     4674       +1     
==========================================
+ Hits        17119    17131      +12     
- Misses      12324    12328       +4     
  Partials     1808     1808              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

harsh62
harsh62 previously approved these changes Nov 17, 2025
Copy link
Member

@harsh62 harsh62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Updated changelog to indicate critical version deprecation for releases 2.30.3 and 2.30.2.
@tylerjroach tylerjroach merged commit d267437 into main Nov 17, 2025
17 of 18 checks passed
@tylerjroach tylerjroach deleted the tjroach/fix-token-serialization branch November 17, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants