mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
FIX OF ALL ISSUES WITH LOG IN PAGE. EVERYTHING TO THE POINT OF TESTING THE MAP WORKS SO FAR.
This commit is contained in:
1 parent
84f010cb87
commit
c79a9636a7
10 files changed
+228
-233
No files matched your search
@@ -14,6 +14,9 @@ export default function TeamPage({ params }) {
|
||||
const router = useRouter();
|
||||
const { teamId } = params;
|
||||
|
||||
// Use the authenticated teamId if available
|
||||
const effectiveTeamId = session?.user?.teamId || teamId;
|
||||
|
||||
const checkHuntStatus = useCallback(async () => {
|
||||
try {
|
||||
const response = await fetch("/api/hunt-status", {
|
||||
@@ -33,11 +36,11 @@ export default function TeamPage({ params }) {
|
||||
|
||||
const fetchTeamData = useCallback(async () => {
|
||||
try {
|
||||
if (!teamId || isNaN(parseInt(teamId, 10))) {
|
||||
if (!effectiveTeamId || isNaN(parseInt(effectiveTeamId, 10))) {
|
||||
throw new Error("Invalid team ID");
|
||||
}
|
||||
|
||||
// First check if the user is still part of this team by fetching current user data
|
||||
// Validate current user data against effectiveTeamId
|
||||
const userResponse = await fetch("/api/user", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
@@ -50,26 +53,32 @@ export default function TeamPage({ params }) {
|
||||
const userData = await userResponse.json();
|
||||
|
||||
// If the user is not in this team anymore, redirect to team selection
|
||||
if (!userData.teamId || userData.teamId != teamId) {
|
||||
if (
|
||||
!userData.teamId ||
|
||||
parseInt(userData.teamId, 10) !== parseInt(effectiveTeamId, 10)
|
||||
) {
|
||||
console.log("User no longer in team, redirecting to team selection");
|
||||
window.location.href = "/team-selection";
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Fetching team data for team ID:", teamId);
|
||||
console.log("Fetching team data for team ID:", effectiveTeamId);
|
||||
|
||||
// Add timestamp to URL to ensure fresh data on every request
|
||||
const timestamp = new Date().getTime();
|
||||
const response = await fetch(`/api/teams/${teamId}?_t=${timestamp}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
},
|
||||
credentials: "include",
|
||||
cache: "no-store",
|
||||
});
|
||||
const response = await fetch(
|
||||
`/api/teams/${effectiveTeamId}?_t=${timestamp}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
},
|
||||
credentials: "include",
|
||||
cache: "no-store",
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const text = await response.text();
|
||||
@@ -95,6 +104,8 @@ export default function TeamPage({ params }) {
|
||||
setTeam(data.team);
|
||||
setTeamMembers(data.members || []);
|
||||
setError("");
|
||||
|
||||
await checkHuntStatus();
|
||||
} catch (err) {
|
||||
console.error("Team page error:", err);
|
||||
setError(err.message);
|
||||
@@ -105,13 +116,11 @@ export default function TeamPage({ params }) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
await checkHuntStatus();
|
||||
}, [teamId, router, checkHuntStatus]);
|
||||
}, [effectiveTeamId, router, checkHuntStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
// Only attempt to fetch data when session is ready and we have a teamId
|
||||
if (status === "authenticated" && teamId) {
|
||||
if (status === "authenticated" && effectiveTeamId) {
|
||||
console.log("Session authenticated, fetching team data");
|
||||
fetchTeamData();
|
||||
|
||||
@@ -124,7 +133,7 @@ export default function TeamPage({ params }) {
|
||||
console.log("User not authenticated, redirecting to login");
|
||||
router.push("/login");
|
||||
}
|
||||
}, [teamId, status, fetchTeamData, router]);
|
||||
}, [effectiveTeamId, status, fetchTeamData, router]);
|
||||
|
||||
if (status === "loading" || loading) {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user