Skip to content

fix(yt): ensure clean logout, purge WebView cookies/storage, and stop auto-reconnection - #352

Merged
ajisth69 merged 1 commit into
mainfrom
fix/yt-logout-session-clear
Oct 18, 2026
Merged

ajisth69 merged 1 commit into
mainfrom
fix/yt-logout-session-clear

Conversation

@ajisth69

Copy link
Copy Markdown
Member

Overview

Resolves the issue where logging out / disconnecting from YouTube Music did not work, left lingering cookies in the WebView, or immediately re-connected the previous account.

Root Causes Identified

  1. CookieManager.removeAllCookies was fire-and-forget: In YtMusicAuthManager.signOut(), removeAllCookies(null) was invoked asynchronously without awaiting completion or wiping HTML5 WebStorage, leaving residual session cookies and tokens in the WebView's cookie jar.
  2. refreshCookiesFromCookieManager resurrected disconnected accounts: refreshCookiesFromCookieManager() lacked a guard on current.isConnected. Any background sync pass or API retry would re-read un-cleared cookies from CookieManager and auto-save the connection right back into preferences.
  3. Premature cookie capture on Google login/account chooser: YouTubeLoginScreen's polling loop and webViewClient captured cookies on any URL as long as SAPISID was present, even while the user was on accounts.google.com trying to choose a different account.

Changes

  • YtMusicAuthManager.kt:
    • Optimistically set _connection.value = YtConnection.DISCONNECTED immediately on signOut().
    • Run on Dispatchers.Main and suspend until CookieManager.getInstance().removeAllCookies completes, then flush() and deleteAllData() on WebStorage.
    • Guard refreshCookiesFromCookieManager() with if (!current.isConnected) return false so disconnected sessions are never revived.
  • SettingsViewModel.kt:
    • Clear _ytChannels.value = emptyList() on disconnectYouTube().
    • Ensure confirmClearAllData() clears the YouTube session via ytAuthManager.signOut().
  • YouTubeLoginScreen.kt:
    • Purge stale cookies and WebStorage upon entering the login screen.
    • Ensure session auto-capture only triggers when the redirect reaches music.youtube.com (or manually via 'I'm signed in').

… auto-reconnection

- Optimistically set _connection to DISCONNECTED and synchronously await CookieManager.removeAllCookies and WebStorage.deleteAllData on Main dispatcher
- Guard refreshCookiesFromCookieManager so disconnected accounts are never resurrected by background sync or retries
- Clear stale cookies/storage on YouTubeLoginScreen entry and ensure auto-capture only triggers when reaching music.youtube.com
- Reset channel options on disconnect and call ytAuthManager.signOut() on confirmClearAllData
@ajisth69
ajisth69 merged commit fb30962 into main Oct 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant