Compare commits

...

2 Commits

@ -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) {

@ -0,0 +1,11 @@
import { store } from "../store.mjs";
export const auth = (req, res, next) => {
const accessToken = req.headers['access-token'];
res.locals.user = store.users.find(user => user.accessToken === accessToken);
if (!res.locals.user) {
res.status(401);
res.send({ message: 'unauthorized' });
}
else next();
};

@ -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",

@ -1 +1 @@
Subproject commit a86bd04da25c3715e7853cd1158b7e4929eacad4 Subproject commit e4de1997a3c34a9fb96136e82446ee926104c3d0
Loading…
Cancel
Save