Arctic

Spotify

For usage, see OAuth 2.0 provider.

import { Spotify } from "arctic";

const spotify = new Spotify(clientId, clientSecret, redirectURI);
const url: URL = await spotify.createAuthorizationURL(state, {
	// optional
	scopes
});
const tokens: SpotifyTokens = await spotify.validateAuthorizationCode(code);
const tokens: SpotifyTokens = await spotify.refreshAccessToken(refreshToken);

Get user profile

Use the /users/me endpoint.

const tokens = await spotify.validateAuthorizationCode(code);
const response = await fetch("https://api.spotify.com/v1/me", {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`
	}
});
const user = await response.json();