fix: safe-parse query schema in signup page to avoid zod throw (#18927)

This commit is contained in:
Benny Joo
2025-01-28 10:15:19 +01:00
committed by GitHub
parent d8c9d2ad94
commit f2d12a4c21
+4 -5
View File
@@ -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,
},
})
),