mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-07 19:30:07 -05:00
fca5a808fb
# Conflicts: # apps/web/app/(app)/(onboarding)/environments/[environmentId]/connect/page.tsx # apps/web/app/(app)/(onboarding)/environments/[environmentId]/xm-templates/page.tsx # apps/web/app/(app)/(onboarding)/organizations/[organizationId]/workspaces/new/settings/page.tsx # apps/web/app/(app)/environments/[environmentId]/actions.ts # apps/web/app/(app)/environments/[environmentId]/components/EnvironmentLayout.tsx # apps/web/app/(app)/environments/[environmentId]/settings/(account)/layout.tsx # apps/web/app/(app)/environments/[environmentId]/settings/(organization)/layout.tsx # apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/emailTemplate.tsx # apps/web/modules/ee/contacts/[contactId]/components/activity-section.tsx # apps/web/modules/ee/contacts/components/contacts-secondary-navigation.tsx # apps/web/modules/ee/contacts/layout.tsx # apps/web/modules/ee/whitelabel/remove-branding/actions.ts # apps/web/modules/environments/lib/utils.test.ts # apps/web/modules/environments/lib/utils.ts # apps/web/modules/projects/settings/general/components/delete-project.tsx # apps/web/modules/survey/editor/page.tsx # apps/web/modules/survey/list/page.tsx # apps/web/modules/survey/templates/page.tsx # apps/web/modules/workspaces/settings/actions.ts # apps/web/modules/workspaces/settings/look/page.tsx
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { getServerSession } from "next-auth";
|
|
import { redirect } from "next/navigation";
|
|
import { AuthenticationError, AuthorizationError, ResourceNotFoundError } from "@formbricks/types/errors";
|
|
import { hasUserEnvironmentAccess } from "@/lib/environment/auth";
|
|
import { getMembershipByUserIdOrganizationId } from "@/lib/membership/service";
|
|
import { getAccessFlags } from "@/lib/membership/utils";
|
|
import { getOrganizationByEnvironmentId } from "@/lib/organization/service";
|
|
import { getWorkspaceByEnvironmentId } from "@/lib/workspace/service";
|
|
import { getTranslate } from "@/lingodotdev/server";
|
|
import { authOptions } from "@/modules/auth/lib/authOptions";
|
|
|
|
const ConfigLayout = async (props: {
|
|
params: Promise<{ environmentId: string }>;
|
|
children: React.ReactNode;
|
|
}) => {
|
|
const params = await props.params;
|
|
|
|
const { children } = props;
|
|
|
|
const t = await getTranslate();
|
|
const [organization, session] = await Promise.all([
|
|
getOrganizationByEnvironmentId(params.environmentId),
|
|
getServerSession(authOptions),
|
|
]);
|
|
|
|
if (!organization) {
|
|
throw new ResourceNotFoundError(t("common.organization"), null);
|
|
}
|
|
|
|
if (!session) {
|
|
throw new AuthenticationError(t("common.not_authenticated"));
|
|
}
|
|
|
|
const hasAccess = await hasUserEnvironmentAccess(session.user.id, params.environmentId);
|
|
if (!hasAccess) {
|
|
throw new AuthorizationError(t("common.not_authorized"));
|
|
}
|
|
|
|
const currentUserMembership = await getMembershipByUserIdOrganizationId(session.user.id, organization.id);
|
|
const { isBilling } = getAccessFlags(currentUserMembership?.role);
|
|
|
|
if (isBilling) {
|
|
return redirect(`/environments/${params.environmentId}/settings/billing`);
|
|
}
|
|
|
|
const workspace = await getWorkspaceByEnvironmentId(params.environmentId);
|
|
if (!workspace) {
|
|
throw new ResourceNotFoundError(t("common.workspace"), null);
|
|
}
|
|
|
|
return children;
|
|
};
|
|
|
|
export default ConfigLayout;
|