fixed all issues regarding team's member list page where users couldn't leave properly or where they couldn't join properly. the team selection page will now directly communicate with the database to ensure everything stays up to date. The team member list page will also auto update every few seconds so the user will not have to manually update their page.

This commit is contained in:
bobbert committed 2025-03-12 22:18:19 +00:00
1 parent 10c117e223
commit 673ea41a4c
11 files changed
+373 -36

No files matched your search

+31 -8
View File
@@ -1,9 +1,12 @@
// app/api/user/route.js
import { queryOne } from "@/lib/db";
import { cookies } from "next/headers";
export const dynamic = "force-dynamic"; // Disable caching
export async function GET() {
try {
// Get the token from cookies - Fix: await the cookies() call
// Get the token from cookies
const cookieStore = await cookies();
const sessionToken = cookieStore.get("next-auth.session-token")?.value;
@@ -11,7 +14,7 @@ export async function GET() {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
// Import the token verification function - using a direct import
// Import the token verification function
const { verifyToken } = await import("../auth/[...nextauth]/route");
try {
@@ -21,12 +24,32 @@ export async function GET() {
return Response.json({ error: "Invalid session" }, { status: 401 });
}
return Response.json({
id: userData.id,
username: userData.username,
role: userData.role,
teamId: userData.teamId,
});
// Always fetch the latest user data from the database to ensure it's accurate
const freshUserData = await queryOne(
"SELECT id, username, role, team_id FROM users WHERE id = ?",
[userData.id]
);
if (!freshUserData) {
return Response.json({ error: "User not found" }, { status: 404 });
}
return Response.json(
{
id: freshUserData.id,
username: freshUserData.username,
role: freshUserData.role,
teamId: freshUserData.team_id,
timestamp: new Date().toISOString(), // Add timestamp for debugging
},
{
headers: {
"Cache-Control": "no-store, must-revalidate",
Pragma: "no-cache",
Expires: "0",
},
}
);
} catch (tokenError) {
console.error("Token verification error:", tokenError);
return Response.json({ error: "Invalid session token" }, { status: 401 });