mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 19:39:01 -05:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 506323aed4 |
@@ -52,15 +52,22 @@ export const EnvironmentContextWrapper = ({
|
|||||||
organization,
|
organization,
|
||||||
children,
|
children,
|
||||||
}: EnvironmentContextWrapperProps) => {
|
}: EnvironmentContextWrapperProps) => {
|
||||||
const environmentContextValue = useMemo(
|
const environmentContextValue = useMemo(() => {
|
||||||
() => ({
|
if (!environment?.id || !project?.id || !organization?.id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
environment,
|
environment,
|
||||||
project,
|
project,
|
||||||
organization,
|
organization,
|
||||||
organizationId: project.organizationId,
|
organizationId: project.organizationId,
|
||||||
}),
|
};
|
||||||
[environment, project, organization]
|
}, [environment, project, organization]);
|
||||||
);
|
|
||||||
|
if (!environmentContextValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EnvironmentContext.Provider value={environmentContextValue}>{children}</EnvironmentContext.Provider>
|
<EnvironmentContext.Provider value={environmentContextValue}>{children}</EnvironmentContext.Provider>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { getServerSession } from "next-auth";
|
import { getServerSession } from "next-auth";
|
||||||
import { redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
|
import { AuthorizationError } from "@formbricks/types/errors";
|
||||||
import { EnvironmentLayout } from "@/app/(app)/environments/[environmentId]/components/EnvironmentLayout";
|
import { EnvironmentLayout } from "@/app/(app)/environments/[environmentId]/components/EnvironmentLayout";
|
||||||
import { EnvironmentContextWrapper } from "@/app/(app)/environments/[environmentId]/context/environment-context";
|
import { EnvironmentContextWrapper } from "@/app/(app)/environments/[environmentId]/context/environment-context";
|
||||||
import { authOptions } from "@/modules/auth/lib/authOptions";
|
import { authOptions } from "@/modules/auth/lib/authOptions";
|
||||||
@@ -20,8 +21,18 @@ const EnvLayout = async (props: {
|
|||||||
return redirect(`/auth/login`);
|
return redirect(`/auth/login`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single consolidated data fetch (replaces ~12 individual fetches)
|
// Handle AuthorizationError gracefully during rapid navigation
|
||||||
const layoutData = await getEnvironmentLayoutData(params.environmentId, session.user.id);
|
let layoutData;
|
||||||
|
try {
|
||||||
|
layoutData = await getEnvironmentLayoutData(params.environmentId, session.user.id);
|
||||||
|
} catch (error) {
|
||||||
|
// If user doesn't have access, show not found instead of crashing
|
||||||
|
if (error instanceof AuthorizationError) {
|
||||||
|
return notFound();
|
||||||
|
}
|
||||||
|
// Re-throw other errors
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EnvironmentIdBaseLayout
|
<EnvironmentIdBaseLayout
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { LoadingSpinner } from "@/modules/ui/components/loading-spinner";
|
||||||
|
|
||||||
|
export default function EnvironmentLoading() {
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen min-h-screen items-center justify-center">
|
||||||
|
<LoadingSpinner className="h-8 w-8" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user