feat: add state to discord ouath

This commit is contained in:
TheClashFruit 2024-08-29 16:29:23 +02:00
parent 4880cfe613
commit 004734ea24
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
2 changed files with 10 additions and 2 deletions

View file

@ -54,6 +54,8 @@ export default function NavBar({ currentPage }: { currentPage: string }) {
url.searchParams.append('redirect_uri', publicRuntimeConfig.discord.redirectUri);
url.searchParams.append('scope', publicRuntimeConfig.discord.scopes.join(' '));
url.searchParams.append('state', router.asPath);
return url.toString();
};

View file

@ -17,7 +17,9 @@ export default async function handler(
) {
const db = new Database();
const { code } = req.query;
const { code, state } = req.query;
console.log(code, state);
const discordApi = process.env.DISCORD_API!;
@ -46,7 +48,11 @@ export default async function handler(
});
res.setHeader('Set-Cookie', cookie);
res.redirect('/');
if ((state as string).startsWith('/'))
res.status(302).redirect(state as string);
else
res.status(400).json({ error: 'Invalid redirect uri in state!' });
}
return;