signOut method
Implementation
@override
Future<Either<AuthServiceSignOutFailure, Unit>> signOut({bool useFbAuthAlso = true}) async {
// Clear cached auth state immediately
_updateCachedState(false);
// Cancel any pending completers
if (_loginCheckCompleter != null && !_loginCheckCompleter!.isCompleted) {
_safeCompleteLoginCheckWithError('User signed out');
}
// ...existing signOut code...
try {
if (useFbAuthAlso) {
await _fbAuth.signOut();
}
// Call the optional callback
await onLoggedOut?.call();
// Clear the cookie on the server if using federated auth
if (AppConfigBase.useCookieFederatedAuth) {
final http.Client client = http.Client();
final response = await client
.get(Uri.parse(RepoHelpers.getFunctionUrl(_fbAuth.app, 'authfunctions-signout')));
if (response.statusCode == 204) {
logd('Cleared cookie successfully');
} else {
logd('Failed to clear cookie!!');
// Don't return error for cookie clear failure
}
}
// Clear the stored user info
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove(sharedPrefKeyFcmToken);
await prefs.remove(sharedPrefKeyTimezone);
_hasInitializedFCM = false;
_accessCodeCached = null;
} on fb_auth.FirebaseAuthException catch (e) {
loge(e);
return left(AuthServiceSignOutFailure.unexpected);
} catch (e) {
loge(e);
return left(AuthServiceSignOutFailure.unexpected);
}
return right(unit);
}