spotify-web-api-js icon indicating copy to clipboard operation
spotify-web-api-js copied to clipboard

Making Multiple Instances of the Wrapper

Open parsasaeedi opened this issue 3 years ago • 2 comments

I'm creating an app where I need 2 instances of the wrapper, one for each user/access-token. But when I make 2 instances, it seems like they are both the same instance.

let SpotifyWebApi = require('spotify-web-api-js');
let spotifyApi1 = new SpotifyWebApi();
let spotifyApi2 = new SpotifyWebApi();

console.log(spotifyApi1.getAccessToken());
console.log(spotifyApi2.getAccessToken());

spotifyApi1.setAccessToken("Hello");
spotifyApi2.setAccessToken("Bye");

console.log(spotifyApi1.getAccessToken());
console.log(spotifyApi2.getAccessToken());

prints:

null
null
Bye
Bye

Where I expected it to print:

null
null
Hello
Bye

The access token in both instances is set to the latest set statement.

Same thing even if I write:

let SpotifyWebApi1 = require('spotify-web-api-js');
let SpotifyWebApi2 = require('spotify-web-api-js');
let spotifyApi1 = new SpotifyWebApi1();
let spotifyApi2 = new SpotifyWebApi2();

I don't know if this is a problem with the wrapper, or my lacking JavaScript skills. But I can't find a generic JavaScript answer on StackOverflow.

Additional context I'm making a react app and I installed the wrapper package using npm. Here is my project. I instantiate the wrappers in /src/Interspot.js and use them in /src/useSpotifyAPI.js

parsasaeedi avatar Aug 20 '22 22:08 parsasaeedi

https://stackoverflow.com/questions/73430871/making-multiple-instances-of-spotify-web-api-js

parsasaeedi avatar Aug 21 '22 00:08 parsasaeedi

@parsasaeedi Yes, this looks definitely like a problem as your use case should be supported. This is a bug that should be addressed.

JMPerez avatar Aug 21 '22 06:08 JMPerez