Skip to content

Commit

Permalink
Merge pull request #37 from IzzyDotExe/redirect-fix
Browse files Browse the repository at this point in the history
Add redirect to the link you were following
  • Loading branch information
IzzyDotExe committed Jul 3, 2024
2 parents 208d112 + cf2c993 commit a15e477
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 4 additions & 2 deletions arc3-api/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ 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)) {
res.sendFile(file, {root: process.env.BUILD_PATH?? "./build"})
return;
}

res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" });
authenticated(req, res, () => {
res.sendFile('index.html', { root: process.env.BUILD_PATH?? "./build" });
});

});

Expand Down
21 changes: 17 additions & 4 deletions arc3-api/src/auth/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand All @@ -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;

Expand Down Expand Up @@ -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('/')

}

Expand Down
2 changes: 1 addition & 1 deletion arc3-api/src/auth/middlewares/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a15e477

Please sign in to comment.