Repository navigation
v0.2.9 - Session Persistence
✨ New Features
Session Persistence
- ✅ Built-in session persistence - Sessions automatically persist across app restarts
- ✅ Secure by default - Uses
flutter_secure_storagefor encrypted token storage - ✅ Graceful fallback - Falls back to
shared_preferencesif secure storage unavailable - ✅ Opt-in with one flag - Enable with
enableSessionPersistence: truein 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 abstractionslib/src/auth/auth_manager.dart- Added session storage integrationlib/src/core/instant_db.dart- Added session restoration on initlib/src/core/types.dart- AddedenableSessionPersistenceconfig flagpubspec.yaml- Added optional dependencies (flutter_secure_storage, shared_preferences)test/auth_integration_test.dart- Added session persistence testsREADME.md- Added session persistence documentation