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");
}
}
Clears all cookies and storage data related to Spotify authentication
Performs a thorough cleaning of browser session data by:
This function is particularly important when:
The function handles errors gracefully and logs all actions for debugging purposes.