Skip to content

Commit

Permalink
fix: validate string before fetching survey (formbricks#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamPalriwala authored Nov 30, 2023
1 parent e53e04c commit 05884ea
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/web/app/s/[surveyId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TResponse } from "@formbricks/types/responses";
import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { getEmailVerificationStatus } from "./lib/helpers";
import { ZId } from "@formbricks/types/environment";

interface LinkSurveyPageProps {
params: {
Expand All @@ -27,6 +28,11 @@ interface LinkSurveyPageProps {
}

export async function generateMetadata({ params }: LinkSurveyPageProps): Promise<Metadata> {
const validId = ZId.safeParse(params.surveyId);
if (!validId.success) {
notFound();
}

const survey = await getSurvey(params.surveyId);

if (!survey || survey.type !== "link" || survey.status === "draft") {
Expand Down Expand Up @@ -74,6 +80,10 @@ export async function generateMetadata({ params }: LinkSurveyPageProps): Promise
}

export default async function LinkSurveyPage({ params, searchParams }: LinkSurveyPageProps) {
const validId = ZId.safeParse(params.surveyId);
if (!validId.success) {
notFound();
}
const survey = await getSurvey(params.surveyId);

const suId = searchParams.suId;
Expand Down

0 comments on commit 05884ea

Please sign in to comment.