Skip to content

Commit

Permalink
UserProfile: handle edge case for routes writing /edit in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiramtilakiiit committed Dec 10, 2024
1 parent 4f963e4 commit 058d1fc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/app/profile/[id]/edit/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { redirect, notFound } from "next/navigation";

import { getClient } from "gql/client";
import { GET_USER_PROFILE } from "gql/queries/users";
import { GET_MEMBERSHIPS } from "gql/queries/clubs";

import { Container } from "@mui/material";

Expand All @@ -26,7 +27,22 @@ export default async function EditProfile({ params }) {
);
const user = { ...userMeta, ...userProfile };

if (userProfile === null || userMeta === null) {

// get memberships if user is a person
let memberships = [];
const {
data: { memberRoles },
} = await getClient().query(GET_MEMBERSHIPS, {
uid: id,
});

// get list of memberRoles.roles along with member.cid
memberships = memberRoles.reduce(
(cv, m) => cv.concat(m.roles.map((r) => ({ ...r, cid: m.cid }))),
[],
);

if ((memberships?.length === 0 && currentUser?.uid !== user.uid) || userProfile === null || userMeta === null) {
notFound();
}
// console.log(user);
Expand Down

0 comments on commit 058d1fc

Please sign in to comment.