Skip to content

Making Multiple Instances of the Wrapper #216

Open
@parsasaeedi

Description

@parsasaeedi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions