@@ -34,6 +34,7 @@ import 'package:flutter/foundation.dart' show debugPrint;
3434
3535import 'package:encrypter_plus/encrypter_plus.dart' ;
3636import 'package:fast_rsa/fast_rsa.dart' show KeyPair;
37+ import 'package:http/http.dart' as http;
3738import 'package:intl/intl.dart' ;
3839import 'package:jwt_decoder/jwt_decoder.dart' ;
3940import 'package:path/path.dart' as path;
@@ -518,6 +519,49 @@ Future<bool> logoutPod() async {
518519 }
519520}
520521
522+ /// Clear all login state without opening a browser.
523+ ///
524+ /// Performs the same cleanup as [logoutPod] but invalidates the IdP session
525+ /// via a headless HTTP request rather than launching a visible browser
526+ /// window. Use this when switching accounts or recovering from stale
527+ /// credentials.
528+
529+ Future <bool > silentLogout () async {
530+ try {
531+ await KeyManager .clear ();
532+
533+ final logoutUrl = await AuthDataManager .getLogoutUrl ();
534+ final authDataRemoved = await AuthDataManager .removeAuthData ();
535+
536+ if (_onLogoutClearCaches != null ) {
537+ try {
538+ await _onLogoutClearCaches !();
539+ } on Object catch (e) {
540+ debugPrint ('silentLogout() cache callback failed (non-critical): $e ' );
541+ }
542+ }
543+
544+ // Best-effort IdP session invalidation via headless HTTP GET.
545+
546+ if (logoutUrl != null && logoutUrl.isNotEmpty) {
547+ try {
548+ await http.get (Uri .parse (logoutUrl));
549+ } on Object catch (e) {
550+ debugPrint ('silentLogout() headless logout failed (non-critical): $e ' );
551+ }
552+ }
553+
554+ return authDataRemoved;
555+ } on Object catch (e) {
556+ debugPrint ('silentLogout() CRITICAL: $e ' );
557+ try {
558+ await AuthDataManager .removeAuthData ();
559+ await KeyManager .clear ();
560+ } on Object catch (_) {}
561+ return false ;
562+ }
563+ }
564+
521565/// Removes header and footer (which mess up the TTL format) from a PEM-formatted public key string.
522566///
523567/// This function takes a public key string, typically in PEM format, and removes
0 commit comments