Skip to content

Commit

Permalink
Improve Authorization Checks in Layout (formbricks#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattinannt committed Jul 5, 2023
1 parent 4af8f90 commit b3f9622
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/web/app/environments/[environmentId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
import PosthogIdentify from "./PosthogIdentify";
import FormbricksClient from "../../FormbricksClient";
import { PosthogClientWrapper } from "../../PosthogClientWrapper";
import { hasUserEnvironmentAccess } from "@/lib/api/apiHelper";

export default async function EnvironmentLayout({ children, params }) {
const session = await getServerSession(authOptions);
if (!session) {
return redirect(`/auth/login`);
}
const hasAccess = await hasUserEnvironmentAccess(session.user, params.environmentId);
if (!hasAccess) {
throw new Error("User does not have access to this environment");
}

return (
<>
Expand Down
5 changes: 3 additions & 2 deletions apps/web/app/environments/[environmentId]/people/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EmptySpaceFiller from "@/components/shared/EmptySpaceFiller";
import { truncateMiddle } from "@/lib/utils";
import { TransformPersonOutput, getPeople } from "@formbricks/lib/services/person";
import { PersonAvatar } from "@formbricks/ui";
import Link from "next/link";

const getAttributeValue = (person: TransformPersonOutput, attributeName: string) =>
person.attributes[attributeName]?.toString();
Expand All @@ -23,7 +24,7 @@ export default async function PeoplePage({ params }) {
<div className="col-span-2 text-center">Email</div>
</div>
{people.map((person) => (
<a
<Link
href={`/environments/${params.environmentId}/people/${person.id}`}
key={person.id}
className="w-full">
Expand Down Expand Up @@ -53,7 +54,7 @@ export default async function PeoplePage({ params }) {
<div className="ph-no-capture text-slate-900">{getAttributeValue(person, "email")}</div>
</div>
</div>
</a>
</Link>
))}
</div>
)}
Expand Down

0 comments on commit b3f9622

Please sign in to comment.