refresh spotify api token; auto reload currentlyPlaying

master
adb-sh 2 years ago
parent c8185bb5c0
commit 3e42a7c37b

@ -27,7 +27,9 @@ export const applyAuthRoutes = (router) => {
const tokens = (await axios.post('https://accounts.spotify.com/api/token', params, config))?.data; const tokens = (await axios.post('https://accounts.spotify.com/api/token', params, config))?.data;
const client = await Client.create({ const newClient = await Client.create({
refreshToken: true,
retryOnRateLimit: true,
token: { token: {
clientID: store.clientID, clientID: store.clientID,
clientSecret: store.clientSecret, clientSecret: store.clientSecret,
@ -35,9 +37,13 @@ export const applyAuthRoutes = (router) => {
refreshToken: tokens.refresh_token, refreshToken: tokens.refresh_token,
}, },
}); });
const player = new Player(client); const player = new Player(newClient);
const accessToken = randomString(64); const accessToken = randomString(64);
store.users.push({ client, player, accessToken, listeners: [], role: 'none' }); const user = store.users.find(({ client }) => client.user.id === newClient.user.id);
if (user) {
user.client = newClient;
}
store.users.push({ client: newClient, player, accessToken, listeners: [], role: 'none' });
res.status(200); res.status(200);
res.send({ message: 'authorized', accessToken }); res.send({ message: 'authorized', accessToken });
} catch (e) { } catch (e) {

@ -1,12 +1,12 @@
{ {
"name": "spot2gether", "name": "spot2gether",
"version": "1.0.0", "version": "0.1.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "spot2gether", "name": "spot2gether",
"version": "1.0.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"axios": "^0.27.2", "axios": "^0.27.2",
"express": "^4.18.1", "express": "^4.18.1",

Loading…
Cancel
Save