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

+26 -5
View File
@@ -1,6 +1,6 @@
import { queryOne, run } from "@/lib/db";
import { cookies } from "next/headers";
import { verifyToken } from "@/app/api/auth/[...nextauth]/route";
import { verifyToken, createToken } from "@/app/api/auth/[...nextauth]/route";
export async function POST(request) {
try {
@@ -36,13 +36,34 @@ export async function POST(request) {
userData.id,
]);
return Response.json(
{
// Create a new token with updated user data
const newUserData = {
...userData,
teamId: team.id, // Update team association in token
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60, // 30 days
};
const newToken = createToken(newUserData);
// Calculate expiration date for cookie
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + 30);
// Return success with updated session token
return new Response(
JSON.stringify({
teamId: team.id,
teamName: team.name,
success: true,
},
{ status: 200 }
}),
{
status: 200,
headers: {
"Content-Type": "application/json",
"Set-Cookie": `next-auth.session-token=${newToken}; Path=/; HttpOnly; SameSite=Lax; Expires=${expiryDate.toUTCString()}`,
},
}
);
} catch (error) {
console.error("Join team error:", error);