diff --git a/components/NavBar.tsx b/components/NavBar.tsx index 4a39199..a8d369f 100644 --- a/components/NavBar.tsx +++ b/components/NavBar.tsx @@ -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(); }; diff --git a/pages/api/v1/auth.ts b/pages/api/v1/auth.ts index 2bf0709..8139a22 100644 --- a/pages/api/v1/auth.ts +++ b/pages/api/v1/auth.ts @@ -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;