Skip to content

v0.2.9 - Session Persistence

Choose a tag to compare

@pillowsoft pillowsoft released this 02 Jan 22:46
· 9 commits to main since this release

✨ New Features

Session Persistence

  • ✅ Built-in session persistence - Sessions automatically persist across app restarts
  • ✅ Secure by default - Uses flutter_secure_storage for encrypted token storage
  • ✅ Graceful fallback - Falls back to shared_preferences if secure storage unavailable
  • ✅ Opt-in with one flag - Enable with enableSessionPersistence: true in config
  • ✅ Fully backward compatible - Disabled by default, no breaking changes
  • ✅ Automatic restoration - Sessions restore on app startup, no manual code needed
  • ✅ Smart error handling - Expired/invalid tokens cleared automatically

How to use:

// 1. Add dependency (choose one):
// flutter_secure_storage: ^9.2.2  (recommended)
// shared_preferences: ^2.3.4      (fallback)

// 2. Enable in config:
final db = await InstantDB.init(
  appId: 'your-app-id',
  config: const InstantConfig(
    enableSessionPersistence: true,
  ),
);

// That's it! Sessions now persist automatically.

🐛 Bug Fixes

Fixed signInWithToken() Type Cast Error

  • ✅ Fixed response format handling - Now handles both flat and nested {user: {...}} response formats
  • ✅ Better error messages - Clearer errors when token validation fails
  • ✅ Robust parsing - Gracefully handles different API response structures

Impact: signInWithToken() now works reliably for session restoration

📝 Documentation

  • Added session persistence guide to README
  • Added security notes for token storage

Files changed:

  • lib/src/auth/session_persistence.dart (NEW) - Session storage abstractions
  • lib/src/auth/auth_manager.dart - Added session storage integration
  • lib/src/core/instant_db.dart - Added session restoration on init
  • lib/src/core/types.dart - Added enableSessionPersistence config flag
  • pubspec.yaml - Added optional dependencies (flutter_secure_storage, shared_preferences)
  • test/auth_integration_test.dart - Added session persistence tests
  • README.md - Added session persistence documentation