signOutWithNativeAuth method
Sign out from Amplify/Cognito (local session only) so the next Hosted UI sign-in can use a different account. Does not open a browser.
Implementation
Future<void> signOutWithNativeAuth(
BuildContext? context, {
bool redirectToLogin = false,
}) async {
if (!Amplify.isConfigured) return;
try {
await TokenStorage.clearTokens();
_refreshTimer?.cancel();
await Amplify.Auth.signOut();
debugPrint('AuthService: native signOut completed successfully');
if (redirectToLogin) {
if (context == null) {
debugPrint(
'AuthService: redirectToLogin requested but context is null; skipping re-auth.');
} else {
await getAccessTokenWithAuth(context);
}
}
} on AuthException catch (e) {
debugPrint('AuthService: native signOut error: ${e.message}');
} catch (e) {
debugPrint('AuthService: native signOut error: $e');
}
}