mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
back to square 1. Now convert the json format info into readable webpage info
This commit is contained in:
1 parent
b039af238f
commit
68e9af2d83
6 files changed
+112
-50
No files matched your search
@@ -19,6 +19,8 @@ export default function TeamPage({ params }) {
|
||||
throw new Error("Invalid team ID");
|
||||
}
|
||||
|
||||
console.log("Fetching team data for team ID:", teamId);
|
||||
|
||||
const response = await fetch(`/api/teams/${teamId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -46,6 +48,7 @@ export default function TeamPage({ params }) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
|
||||
console.log("Team data fetched successfully:", data);
|
||||
setTeam(data.team);
|
||||
setTeamMembers(data.members || []);
|
||||
setError("");
|
||||
@@ -62,12 +65,17 @@ export default function TeamPage({ params }) {
|
||||
}, [teamId, router]);
|
||||
|
||||
useEffect(() => {
|
||||
// Only attempt to fetch data when session is ready and we have a teamId
|
||||
if (status === "authenticated" && teamId) {
|
||||
console.log("Session authenticated, fetching team data");
|
||||
fetchTeamData();
|
||||
const interval = setInterval(fetchTeamData, 5000); // Refresh every 5 seconds
|
||||
return () => clearInterval(interval);
|
||||
} else if (status === "unauthenticated") {
|
||||
console.log("User not authenticated, redirecting to login");
|
||||
router.push("/login");
|
||||
} else {
|
||||
console.log("Waiting for session...", status);
|
||||
}
|
||||
}, [teamId, status, fetchTeamData, router]);
|
||||
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
||||
import { queryOne, query } from "@/lib/db";
|
||||
import { query, queryOne } from "@/lib/db";
|
||||
import { cookies } from "next/headers";
|
||||
import { verifyToken } from "@/app/api/auth/[...nextauth]/route";
|
||||
|
||||
export async function GET(_, context) {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session) {
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
try {
|
||||
// Use our custom token verification instead of getServerSession
|
||||
const cookieStore = await cookies();
|
||||
const sessionToken = cookieStore.get("next-auth.session-token")?.value;
|
||||
|
||||
if (!sessionToken) {
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
const userData = verifyToken(sessionToken);
|
||||
if (!userData) {
|
||||
return redirect("/login");
|
||||
}
|
||||
|
||||
const params = await context.params;
|
||||
const teamId = params.teamId;
|
||||
|
||||
|
||||
Reference in new issue
Block a user