Compare commits

..

No commits in common. "5ecff037dcee798e6768bfc0d38558beb559d440" and "c8185bb5c0409e8e827b7a473f0c3a86c3dc6ca2" have entirely different histories.

4 changed files with 6 additions and 23 deletions

View File

@ -27,9 +27,7 @@ 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 newClient = await Client.create({ const client = await Client.create({
refreshToken: true,
retryOnRateLimit: true,
token: { token: {
clientID: store.clientID, clientID: store.clientID,
clientSecret: store.clientSecret, clientSecret: store.clientSecret,
@ -37,13 +35,9 @@ export const applyAuthRoutes = (router) => {
refreshToken: tokens.refresh_token, refreshToken: tokens.refresh_token,
}, },
}); });
const player = new Player(newClient); const player = new Player(client);
const accessToken = randomString(64); const accessToken = randomString(64);
const user = store.users.find(({ client }) => client.user.id === newClient.user.id); store.users.push({ client, player, accessToken, listeners: [], role: 'none' });
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) {

View File

@ -1,11 +0,0 @@
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();
};

View File

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

@ -1 +1 @@
Subproject commit e4de1997a3c34a9fb96136e82446ee926104c3d0 Subproject commit a86bd04da25c3715e7853cd1158b7e4929eacad4