angular-spotify icon indicating copy to clipboard operation
angular-spotify copied to clipboard

How to store the token after login?

Open mscalessio opened this issue 9 years ago • 1 comments

Hi, thank's for this awesome project! I'm a newbie. So my question will be stupid. Can you help me to understand the perfect login flow to store the token after the login? I'm trying to do it in Angular. So in the main controller, after the user click on the button Login, i can access Spotify to retrive the token and with your example (callback.html) i'm able to store in the localStorage. But after that i can't figure how to use it to make the Authorized api call. Please help me 😰

mscalessio avatar Aug 15 '16 14:08 mscalessio

It should be storing your auth token automatically when you login.

From login() in the source code:

function storageChanged (e) {
              if (e.key === 'spotify-token') {
                if (authWindow) { authWindow.close(); }
                authCompleted = true;

                that.setAuthToken(e.newValue);
                $window.removeEventListener('storage', storageChanged, false);

                deferred.resolve(e.newValue);
              }
            }

Or if for some reason you are wanting the Auth Token after calling Spotify.login(), you can chain a .then() onto Spotify.login() and do whatever you want with your Auth Token like so:

Spotify.login().then((token) => { console.log(token); });

matthamil avatar Sep 17 '16 23:09 matthamil