Spotify API User Authorization

I’m trying to learn how to use APIs in wix and have a few questions about the spotify api.

I was able to get the spotify api tutorial running to search albums and playlists but am confused about how to implement user authentication.

I used this code to get to the authorization screen and receive a code in the redirect url.

var scopes = ['user-read-private', 'user-read-email'], 
redirectUri = 'https://example. com/callback', 
clientId = 'client-id', 
state = 'some-state-of-my-choice'; 

var spotifyApi = new SpotifyWebApi({ redirectUri: redirectUri, clientId: clientId }); 
var authorizeURL = spotifyApi.createAuthorizeURL(scopes, state); 

I thought maybe I could use this to get the code returned in the redirect uri. It gets the code but I’m not sure if it’s how I should be doing it.

let query = wixLocation.query;
let code = query.code

From here I am not sure how to structure my backend file to receive the code and get an access token.

Any help is appreciated. I don’t know if I’m doing any of this right. Thanks.

Reference website:
https://www.npmjs. com/package/spotify-web-api-node