mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
SCANNER WORKS!!! JUST ADD THE MORE CLUE BUTTONS !!! AND NEXT CLUE ERROR CHECKING
This commit is contained in:
1 parent
07099ba6b4
commit
02a0088d28
11 files changed
+861
-217
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { query } from "@/lib/db";
|
||||
import { cookies } from "next/headers";
|
||||
import { verifyToken } from "@/app/api/auth/[...nextauth]/route";
|
||||
|
||||
export async function GET(request, context) {
|
||||
try {
|
||||
const cookieStore = cookies();
|
||||
const token = cookieStore.get("next-auth.session-token")?.value;
|
||||
|
||||
if (!token) {
|
||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const userData = verifyToken(token);
|
||||
if (!userData) {
|
||||
return Response.json({ error: "Invalid session" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { teamId } = context.params;
|
||||
const requestedTeamId = parseInt(teamId, 10);
|
||||
const userTeamId = parseInt(userData.teamId, 10);
|
||||
|
||||
console.log("Requested team:", requestedTeamId);
|
||||
console.log("User team:", userTeamId);
|
||||
console.log("User role:", userData.role);
|
||||
|
||||
// Ensure the user is requesting their own team or is an admin
|
||||
if (userTeamId !== requestedTeamId && userData.role !== "admin") {
|
||||
return Response.json(
|
||||
{ error: "Not authorized to view this team" },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
const teamMembers = await query("SELECT * FROM users WHERE team_id = ?", [
|
||||
requestedTeamId,
|
||||
]);
|
||||
|
||||
if (!teamMembers) {
|
||||
return Response.json(
|
||||
{ error: "Team members not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return Response.json(teamMembers);
|
||||
} catch (error) {
|
||||
console.error("Team members fetch error:", error);
|
||||
return Response.json(
|
||||
{ error: "Failed to fetch team members" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user