From f2d12a4c214ee4ac60c073138fdcfd2b7b283ed4 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Tue, 28 Jan 2025 09:15:19 +0000 Subject: [PATCH] fix: safe-parse query schema in signup page to avoid zod throw (#18927) --- apps/web/lib/signup/getServerSideProps.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/web/lib/signup/getServerSideProps.tsx b/apps/web/lib/signup/getServerSideProps.tsx index d3d2804349..64cd1c06a6 100644 --- a/apps/web/lib/signup/getServerSideProps.tsx +++ b/apps/web/lib/signup/getServerSideProps.tsx @@ -49,9 +49,6 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { emailVerificationEnabled, }; - // username + email prepopulated from query params - const { username: preFillusername, email: prefilEmail } = querySchema.parse(ctx.query); - if ((process.env.NEXT_PUBLIC_DISABLE_SIGNUP === "true" && !token) || signupDisabled) { return { redirect: { @@ -63,13 +60,15 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { // no token given, treat as a normal signup without verification token if (!token) { + // username + email prepopulated from query params + const queryData = querySchema.safeParse(ctx.query); return { props: JSON.parse( JSON.stringify({ ...props, prepopulateFormValues: { - username: preFillusername || null, - email: prefilEmail || null, + username: queryData.success ? queryData.data.username : null, + email: queryData.success ? queryData.data.email : null, }, }) ),