diff --git a/apps/web/app/s/[surveyId]/page.tsx b/apps/web/app/s/[surveyId]/page.tsx
index f786588505..0a097acab3 100644
--- a/apps/web/app/s/[surveyId]/page.tsx
+++ b/apps/web/app/s/[surveyId]/page.tsx
@@ -8,18 +8,17 @@ import { getProductByEnvironmentId } from "@formbricks/lib/services/product";
import SurveyInactive from "@/app/s/[surveyId]/SurveyInactive";
export default async function LinkSurveyPage({ params }) {
- const [survey, product] = await Promise.all([
- getSurvey(params.surveyId),
- getProductByEnvironmentId(params.environmentId),
- ]);
+ const survey = await getSurvey(params.surveyId);
+
+ if (!survey) {
+ return ;
+ }
if (survey && survey.status !== "inProgress") {
return ;
}
- if (survey === null) {
- return ;
- }
+ const product = await getProductByEnvironmentId(survey.environmentId);
return (
<>
diff --git a/packages/lib/services/product.ts b/packages/lib/services/product.ts
index 22fb2047e3..48e6c0bf06 100644
--- a/packages/lib/services/product.ts
+++ b/packages/lib/services/product.ts
@@ -23,6 +23,9 @@ const selectProduct = {
};
export const getProductByEnvironmentId = cache(async (environmentId: string): Promise => {
+ if (!environmentId) {
+ throw new ValidationError("EnvironmentId is required");
+ }
let productPrisma;
try {
productPrisma = await prisma.product.findFirst({