I can't seem to force a sign out of Github or Microsoft they way I do for Google. With the help of the google_sign_in package.
Future<GoogleSignInAccount?> _signOutWithGoogle() async {
return Chain.capture(() async {
try {
return await GoogleSignIn().signOut();
} on Exception catch (error, stackTrace) {
final terseStacktrace = Chain.forTrace(stackTrace).terse;
logger.e(
"GoogleSignOutException",
error: error,
stackTrace: terseStacktrace,
);
rethrow;
}
});
}
Future<Result<void, LogOutFailure>> signOut() async {
try {
if (_auth.currentUser?.providerData.first.providerId == "google.com") {
await _signOutWithGoogle();
}
await _auth.signOut();
return const Result.success(null);
} catch (_) {
return const Result.error(LogOutFailure());
}
}
Without a signout from the package, I'll be automatically logged in as the previous credential I used and I won't be able to change it.
The same issue persists for Microsoft and Github sign ins.
import 'package:firebase_auth/firebase_auth.dart';
Future<UserCredential> signInWithMicrosoft() async {
final microsoftProvider = MicrosoftAuthProvider();
if (kIsWeb) {
await FirebaseAuth.instance.signInWithPopup(microsoftProvider);
} else {
await FirebaseAuth.instance.signInWithProvider(microsoftProvider);
}
}
Calling _auth.signOut()
isn't enough since it only signs out the firebase user not the github or microsoft user.
Is there a package or implementation I can use to solve this?
logoutRedirect
method from the Microsoft Authentication Library (MSAL). This method clears the local cache of user tokens and redirects the window to the server signout page. This is a more comprehensive signout solution.Then, remember to call these methods in your
signOut
method: