mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
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:
1 parent
10c117e223
commit
673ea41a4c
11 files changed
+373
-36
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user