From ada74467bcbe81b04fc2f03c5f19fd5d1135df1a Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:15:50 +0000 Subject: [PATCH] fix: Callback redirect (#12361) --- apps/web/pages/auth/login.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/auth/login.tsx b/apps/web/pages/auth/login.tsx index 780286c47a..1fa1eab0cb 100644 --- a/apps/web/pages/auth/login.tsx +++ b/apps/web/pages/auth/login.tsx @@ -278,7 +278,7 @@ inferSSRProps & WithNonceProps<{}>) { // TODO: Once we understand how to retrieve prop types automatically from getServerSideProps, remove this temporary variable const _getServerSideProps = async function getServerSideProps(context: GetServerSidePropsContext) { - const { req, res } = context; + const { req, res, query } = context; const session = await getServerSession({ req, res }); const ssr = await ssrInit(context); @@ -318,6 +318,24 @@ const _getServerSideProps = async function getServerSideProps(context: GetServer } if (session) { + const { callbackUrl } = query; + + if (callbackUrl) { + try { + const destination = getSafeRedirectUrl(callbackUrl as string); + if (destination) { + return { + redirect: { + destination, + permanent: false, + }, + }; + } + } catch (e) { + console.warn(e); + } + } + return { redirect: { destination: "/",