• Clears all cookies and storage data related to Spotify authentication

    Performs a thorough cleaning of browser session data by:

    1. Removing all Spotify-specific cookies across relevant domains
    2. Clearing all storage types (localStorage, indexedDB, etc.)
    3. Ensuring complete session state reset

    This function is particularly important when:

    • Implementing "Log in with a different account" functionality
    • Ensuring complete logout for security purposes
    • Resolving authentication issues caused by stale session data
    • Forcing the Spotify account selection screen to appear

    The function handles errors gracefully and logs all actions for debugging purposes.

    Returns Promise<void>

    Promise that resolves when all cookies and storage are cleared

    // Force account selection by clearing existing auth data
    await clearSpotifyAuthData();
    startAuthFlow(mainWindow, clientId, clientSecret, redirectUri, true);
    export async function clearSpotifyAuthData(): Promise<void> {
    try {
    saveLog(
    "Clearing Spotify authentication cookies and storage data",
    "DEBUG",
    );

    // Remove all Spotify cookies for each domain
    for (const domain of SPOTIFY_DOMAINS) {
    for (const cookieName of SPOTIFY_COOKIES) {
    try {
    await session.defaultSession.cookies.remove(
    `https://${domain}`,
    cookieName,
    );
    } catch {
    // Ignore errors for cookies that don't exist
    }
    }
    }

    // Clear all storage data for Spotify domains
    await session.defaultSession.clearStorageData({
    origin: `https://accounts.spotify.com`,
    storages: [
    "cookies",
    "filesystem",
    "indexdb",
    "localstorage",
    "shadercache",
    "websql",
    "serviceworkers",
    "cachestorage",
    ],
    });

    saveLog("Successfully cleared Spotify authentication data", "DEBUG");
    } catch (error) {
    saveLog(`Error clearing Spotify auth data: ${error}`, "ERROR");
    }
    }