Skip to content

Commit a0ffbd1

Browse files
authored
feat: add access control for user profiles (#34)
1 parent 67f5e4a commit a0ffbd1

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

app/api/users/[id]/route.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,28 @@ export async function GET(
175175
);
176176
}
177177

178+
// Access control: a profile is public only while the user is "looking for a
179+
// team" (isLooking). Otherwise it is private and visible only to admins,
180+
// evaluators, the user themselves, or their own teammates.
181+
const requester = authResult.user;
182+
const isPrivileged =
183+
requester.role === "admin" || requester.role === "evaluator";
184+
const isSelf = requester.uid === user.uid;
185+
const isTeammate =
186+
!!requester.teamCode &&
187+
!!user.teamCode &&
188+
requester.teamCode === user.teamCode;
189+
190+
if (!user.isLooking && !isPrivileged && !isSelf && !isTeammate) {
191+
return NextResponse.json(
192+
{
193+
message: "This profile is private",
194+
status: "error",
195+
},
196+
{ status: 403 },
197+
);
198+
}
199+
178200
return NextResponse.json({
179201
message: "User found",
180202
status: "success",

0 commit comments

Comments
 (0)