clearTokens method
Clear all tokens.
Both deletes are attempted even when the first one fails, and the first failure is rethrown once both have been tried. A vault delete throws MagicVaultException on a platform error (a locked keychain, a lost entitlement), and stopping at the first would leave the refresh token behind, which is a live session on the next launch.
Implementation
Future<void> clearTokens() async {
Object? failure;
StackTrace? failureStack;
try {
await Vault.delete(tokenKey);
} catch (e, stack) {
failure = e;
failureStack = stack;
}
_cachedToken = null;
if (refreshTokenKey != null) {
try {
await Vault.delete(refreshTokenKey!);
} catch (e, stack) {
failure ??= e;
failureStack ??= stack;
}
}
if (failure != null) Error.throwWithStackTrace(failure, failureStack!);
}