logout method
Logs out the current user from the cloud service.
Implementation
@override
Future<bool> logout() async {
debugPrint("Logging out from OneDrive...");
final cookieManager = CookieManager.instance();
if (_isAuthenticated) {
try {
// 1. Disconnect the client to clear local tokens.
await client.disconnect();
_isAuthenticated = false;
// 2. Clear all WebView cookies to ensure a fresh login prompt on the next connect attempt.
await cookieManager.deleteAllCookies();
debugPrint("OneDrive logout successful and web cookies cleared.");
return true;
} catch (error) {
debugPrint(
"Error during OneDrive logout.",
);
return false;
}
}
// Ensure cookies are cleared even if the client was already disconnected.
await cookieManager.deleteAllCookies();
debugPrint(
"Already logged out from OneDrive, ensuring cookies are cleared.");
return false;
}