From db4b646b0319bbc0cb917952afc1842c16a9e7e6 Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Wed, 3 Jul 2024 12:37:48 -0400 Subject: [PATCH 1/2] Add redirect to the link you were following --- arc3-api/src/app.js | 10 +++++---- .../src/auth/controllers/authentication.js | 21 +++++++++++++++---- .../src/auth/middlewares/authenticated.js | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/arc3-api/src/app.js b/arc3-api/src/app.js index 865079b..09d22fe 100644 --- a/arc3-api/src/app.js +++ b/arc3-api/src/app.js @@ -35,13 +35,13 @@ app.get('/login', (req, res) => { }) // Protect the transcripts route. -app.get('/:guildid/transcripts/', authenticated, whitelist, (req, res) => { +app.get('/:guildid/transcripts/', authenticated, (req, res) => { res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); }) // Protect the transcripts route. -app.get('/:guildid/transcripts/*', authenticated, whitelist, (req, res) => { +app.get('/:guildid/transcripts/*', authenticated, (req, res) => { res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); }) @@ -56,7 +56,7 @@ app.get('/:guildid/notes/*', authenticated, whitelist, (req, res) => { }) // Authenticate the rest of the client. -app.get('/*', authenticated, (req, res) => { +app.get('/*', (req, res, next) => { const file = req.path.split('/')[1]; if (STATIC_FILES.includes(file)) { @@ -64,7 +64,9 @@ app.get('/*', authenticated, (req, res) => { return; } - res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); + authenticated(req, res, () => { + res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); + }); }); diff --git a/arc3-api/src/auth/controllers/authentication.js b/arc3-api/src/auth/controllers/authentication.js index 95c4d3e..53d2133 100644 --- a/arc3-api/src/auth/controllers/authentication.js +++ b/arc3-api/src/auth/controllers/authentication.js @@ -3,13 +3,19 @@ const { Sign, Verify } = require('../../lib/jwt.js'); // Send the login page function LoginRoute(req, res) { - res.redirect("/login"); + const {src} = req.query + if (src) { + res.cookie('src', src) + } + + res.redirect(`/login`); + } function RedirectRoute(req, res) { - // Get the direct url and send them to it - const url = process.env.DIRECT_URL; + let url = process.env.DIRECT_URL; + res.redirect(url); } @@ -23,6 +29,10 @@ async function CallbackRoute(req, res) { return; } + // If there is an src available from this identified user, get it. + + const { src } = req.cookies; + // Extract the code from the query parameters const { code } = req.query; @@ -55,7 +65,10 @@ async function CallbackRoute(req, res) { res.cookie('session', jwt, { maxAge: response.data.expires_in }) - res.redirect('/') + if (src) + res.redirect(src) + else + res.redirect('/') } diff --git a/arc3-api/src/auth/middlewares/authenticated.js b/arc3-api/src/auth/middlewares/authenticated.js index 6bf9029..c410887 100644 --- a/arc3-api/src/auth/middlewares/authenticated.js +++ b/arc3-api/src/auth/middlewares/authenticated.js @@ -18,7 +18,7 @@ async function authenticated(req, res, next) { // If we got no cookies, we can redirect to the login page. if (!token) { - res.redirect('/auth/login'); + res.redirect(`/auth/login?src=${req.originalUrl}`); return; } From cf2c9937142448f9bd5db82d7b41ae7e7c80522c Mon Sep 17 00:00:00 2001 From: izzydotexe Date: Wed, 3 Jul 2024 12:40:10 -0400 Subject: [PATCH 2/2] re-add whitelist to routes --- arc3-api/src/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arc3-api/src/app.js b/arc3-api/src/app.js index 09d22fe..80cbc98 100644 --- a/arc3-api/src/app.js +++ b/arc3-api/src/app.js @@ -35,13 +35,13 @@ app.get('/login', (req, res) => { }) // Protect the transcripts route. -app.get('/:guildid/transcripts/', authenticated, (req, res) => { +app.get('/:guildid/transcripts/', authenticated, whitelist, (req, res) => { res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); }) // Protect the transcripts route. -app.get('/:guildid/transcripts/*', authenticated, (req, res) => { +app.get('/:guildid/transcripts/*', authenticated, whitelist, (req, res) => { res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" }); })