initialize method
Loads the saved refresh token into memory, treating one that cannot be read as one that is not there.
Nothing in here may throw, for the same reason AppstraxAuth.initialize
may not: this runs from initializeAppstraxServices, so an exception
escaping it fails app startup - and because the offending value stays in
storage, it fails on every subsequent launch too, with no way out but
reinstalling. That is a worse outcome than signing in again, whatever the
cause.
The cause is usually the platform rather than us: a KeyStore entry invalidated by a fingerprint being added, ciphertext restored onto a device whose key did not come with it, a locked keyring on Linux, or - the reason this guard was added - a cipher whose backend the plugin has since removed. The unreadable value is cleared, so the next launch starts from a clean slate instead of meeting the same failure.
Implementation
Future<void> initialize() async {
try {
_cachedRefreshToken = await _storage.read(key: _refreshTokenKey);
} catch (err) {
if (kDebugMode) {
debugPrint('Appstrax: could not read the saved session: $err');
}
_cachedRefreshToken = null;
// Best effort. If reading failed, deleting may fail too, and there is
// nothing further to try.
try {
await _storage.delete(key: _refreshTokenKey);
} catch (_) {}
}
}