Files
Benny JooandGitHub 07c8bbc562 fix: crash due to lack of input validation in WizardForm (#21990)
* fix: crash due to lack of input validation in WizardForm

* server side validation

* refactor

* refactor
2025-06-23 17:03:51 -03:00

42 lines
1.3 KiB
TypeScript

import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps as ServerPageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";
import { z } from "zod";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@server/lib/setup/getServerSideProps";
import Setup from "~/auth/setup-view";
import type { PageProps as ClientPageProps } from "~/auth/setup-view";
export const generateMetadata = async () => {
return await _generateMetadata(
(t) => t("setup"),
(t) => t("setup_description"),
undefined,
undefined,
"/auth/setup"
);
};
const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
const stepSchema = z.enum(["1", "2", "3", "4"]);
const ServerPage = async ({ params, searchParams: _searchParams }: ServerPageProps) => {
const searchParams = await _searchParams;
const stepResult = stepSchema.safeParse(searchParams?.step);
// If step parameter is invalid, redirect to step 1
if (!stepResult.success) {
return redirect(`/auth/setup?step=1`);
}
const props = await getData(buildLegacyCtx(await headers(), await cookies(), await params, searchParams));
return <Setup {...props} />;
};
export default ServerPage;