Peter-Schorn/SpotifyAPI

How to know when user logged with a different account in Spotify app?

Closed this issue · 3 comments

Hello!

I've encountered a scenario while testing between premium and free accounts: my authorization manager is kept in the keychain with the old account data, even though I have logged in with a different account.

How can I tell if the user I have in the authorization manager is not the one I am asking to login with?

After retrieving the authorization information for a user, make a request to the SpotifyAPI.currentUserProfile() endpoint and store the the uri property of SpotifyUser along with the authorization information in the keychain. You may also want to store other properties as well, such as displayName, so that you can display the name of the user in your app. The uri property will be unique to each user.

How can I tell if the user I have in the authorization manager is not the one I am asking to login with?

If the person using your app has multiple Spotify accounts, then, when you open the authorization URL that prompts them to login, it's entirely up to them which Spotify account to login with before clicking "agree". It's only after Spotify redirects to your app and you retrieve the authorization information that you can determine which account they decided to login with by making a request to SpotifyAPI.currentUserProfile(), as described above.

Thank you so so much! You're amazing and a life saver.

@zdurlan I just created a branch in my example app that allows you to use multiple accounts. Check it out here.