I’m working on an Android app that lets users link their Spotify accounts. Right now I’m using this code to log in:
AuthenticationClient.openLoginActivity(activity, SPOTIFY_LOGIN_CODE, authRequest)
But I’ve hit a snag. I want to let users switch between different Spotify accounts. The problem is that once they’ve logged in once, the app remembers their info. So when I try to open the login screen again, it just skips it because they’re already signed in.
I checked the docs and they mentioned using AuthenticationClient.clearCookies()
to log out and clear saved tokens. But that method doesn’t seem to exist anymore.
Does anyone know how I can properly log a user out so they can sign in with a different account? I’m stuck and could really use some help! Thanks in advance.
hey luna, i had the same problem! try using SpotifyAppRemote.disconnect()
to log out. then clear any saved tokens in your app. that should force a new login prompt. hope this helps! let me know if u need more info
I’ve faced a similar issue in one of my projects. The clearCookies()
method has indeed been deprecated. Instead, you can use the AuthenticationClient.logout()
method to sign out the user. Here’s how you can implement it:
AuthenticationClient.logout(context)
This will clear the current session and remove any stored tokens. After calling this, when you attempt to open the login activity again, it should prompt for credentials.
Remember to also clear any locally stored user data or tokens in your app after logout. This ensures a clean slate for the next login.
If you’re still having trouble, double-check that you’re using the latest version of the Spotify SDK. They’ve made quite a few changes recently, so staying up-to-date is crucial for smooth integration.
I’ve been through this exact headache with Spotify authentication. What worked for me was a combination of approaches. First, call AuthenticationClient.logout(context)
as mentioned earlier. Then, to be extra thorough, I also cleared WebView data:
WebView(context).clearCache(true)
CookieManager.getInstance().removeAllCookies(null)
CookieManager.getInstance().flush()
This combo seemed to do the trick, forcing a fresh login every time. Also, don’t forget to nullify any access tokens you’ve stored in your app’s preferences or database. It’s a bit of a hassle, but it ensures a clean slate for the next login attempt. If you’re still hitting issues, you might want to check if there’s a Spotify app installed on the device - sometimes that can interfere with the SDK’s auth flow.