feat: add state to discord ouath
This commit is contained in:
parent
4880cfe613
commit
004734ea24
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue