spotify / spotify-web-api-ts-sdk

A Typescript SDK for the Spotify Web API with types for returned data.
Other
355 stars 69 forks source link

What would be a proper way to handle logout? #106

Open tejasvajaitly opened 6 months ago

tejasvajaitly commented 6 months ago

I want to know how can i handle logout. I am using Vite + React + TS.

Right now I am just calling <button onClick={sdk.logOut}>logout</button> But when I click on the button I get this error on the browser console TypeError: Cannot read properties of undefined (reading 'authenticationStrategy')

And indicates that the error is in this function public logOut(): void { this.authenticationStrategy.removeAccessToken(); } which is in the file SpotifyApi.ts

Extra Information: My table content which is right below the logout button works just fine with const results = await sdk.search("The Beatles", ["artist"]); getting proper data.

teboho commented 6 months ago

Try this

<button onClick={() => sdk.logOut()}>logout</button>