Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Multiple Instances of the Wrapper #216

Open
parsasaeedi opened this issue Aug 20, 2022 · 2 comments
Open

Making Multiple Instances of the Wrapper #216

parsasaeedi opened this issue Aug 20, 2022 · 2 comments

Comments

@parsasaeedi
Copy link

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

@JMPerez
Copy link
Owner

JMPerez commented Aug 21, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants