diff --git a/app/(auth)/login/page.js b/app/(auth)/login/page.js
index 9d3a2ed..8dfb23a 100644
--- a/app/(auth)/login/page.js
+++ b/app/(auth)/login/page.js
@@ -32,8 +32,15 @@ export default function Login() {
throw new Error(result.error);
}
- // Success case - redirect
- router.push("/team-selection");
+ // If the user has a team, redirect directly to the team page
+ if (result?.url) {
+ // Extract the teamId from the URL or session data if available
+ // This part depends on how your auth system returns the result
+ router.push(`/${session?.user?.teamId || ""}`);
+ } else {
+ // Otherwise go to team selection
+ router.push("/team-selection");
+ }
return;
} catch (signInError) {
console.error("Error with signIn method:", signInError);
diff --git a/app/(main)/create-team/page.js b/app/(main)/create-team/page.js
index 0695a78..df50595 100644
--- a/app/(main)/create-team/page.js
+++ b/app/(main)/create-team/page.js
@@ -46,7 +46,7 @@ export default function CreateTeam() {
headers: {
"Content-Type": "application/json",
},
- credentials: "include", // Important for cookies
+ credentials: "include",
body: JSON.stringify({ name: teamName }),
});
@@ -56,24 +56,11 @@ export default function CreateTeam() {
throw new Error(data.error || "Failed to create team");
}
- // Force a session update to get the new teamId
- try {
- // Update the client-side session data with the new teamId
- if (session && session.user) {
- session.user.teamId = data.teamId;
- }
-
- console.log("Team created successfully, redirecting to:", `/team/${data.teamId}`);
-
- // Add a small delay to allow session update
- setTimeout(() => {
- router.push(`/team/${data.teamId}`);
- }, 100);
- } catch (navError) {
- console.error("Navigation error:", navError);
- // Fallback to direct navigation
- window.location.href = `/team/${data.teamId}`;
- }
+ // Navigate with the correct URL pattern for the page component
+ console.log("Team created successfully with ID:", data.teamId);
+
+ // Hard navigation to make sure we're going to the page component not the API route
+ window.location.href = `/${data.teamId}`;
} catch (err) {
setError(err.message);
setIsLoading(false);
diff --git a/app/(main)/team-selection/page.js b/app/(main)/team-selection/page.js
index ef704e1..2ae3eab 100644
--- a/app/(main)/team-selection/page.js
+++ b/app/(main)/team-selection/page.js
@@ -14,7 +14,7 @@ export default function TeamSelection() {
useEffect(() => {
if (status === "authenticated") {
if (session.user.teamId) {
- router.push(`/team/${session.user.teamId}`);
+ window.location.href = `/${session.user.teamId}`;
} else {
setIsLoading(false);
}
@@ -41,7 +41,7 @@ export default function TeamSelection() {
throw new Error(data.error || "Failed to join team");
}
- router.push(`/team/${data.teamId}`);
+ window.location.href = `/${data.teamId}`;
} catch (err) {
setError(err.message);
setIsLoading(false);
diff --git a/app/(main)/team/[teamId]/page.js b/app/(main)/team/[teamId]/page.js
index 10cb789..346a516 100644
--- a/app/(main)/team/[teamId]/page.js
+++ b/app/(main)/team/[teamId]/page.js
@@ -20,7 +20,7 @@ export default function TeamPage({ params }) {
}
console.log("Fetching team data for team ID:", teamId);
-
+
const response = await fetch(`/api/teams/${teamId}`, {
method: "GET",
headers: {
@@ -44,11 +44,12 @@ export default function TeamPage({ params }) {
}
const data = await response.json();
+ console.log("Team data received:", data);
+
if (!data.team) {
throw new Error("Team not found");
}
- console.log("Team data fetched successfully:", data);
setTeam(data.team);
setTeamMembers(data.members || []);
setError("");
@@ -69,145 +70,163 @@ export default function TeamPage({ params }) {
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]);
- const handleLeaveTeam = async () => {
- try {
- setLoading(true);
- const response = await fetch(`/api/teams/${teamId}/leave`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- credentials: "include",
- });
-
- if (!response.ok) {
- const errorData = await response.json();
- throw new Error(errorData.error || "Failed to leave team");
- }
-
- // Redirect to team selection after leaving
- router.push("/team-selection");
- } catch (err) {
- console.error("Leave team error:", err);
- setError(err.message);
- } finally {
- setLoading(false);
- }
- };
-
- const handleStartHunt = async () => {
- try {
- if (session?.user?.role !== "admin") {
- setError("Only admins can start a hunt");
- return;
- }
-
- setLoading(true);
- const response = await fetch(`/api/teams/${teamId}/start-hunt`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- credentials: "include",
- });
-
- if (!response.ok) {
- const errorData = await response.json();
- throw new Error(errorData.error || "Failed to start hunt");
- }
-
- // You could redirect to a hunt page or refresh the current page
- // For now, just refresh the team data
- await fetchTeamData();
- } catch (err) {
- console.error("Start hunt error:", err);
- setError(err.message);
- } finally {
- setLoading(false);
- }
- };
-
- const handleAddUser = () => {
- // Navigate to add user page or open a modal
- router.push(`/team/${teamId}/add-user`);
- };
-
if (status === "loading" || loading) {
- return
Loading...
;
+ return (
+
+
+
Loading team data...
+
+ );
}
if (error) {
- return Error: {error}
;
+ return (
+
+
⚠️
+
Error: {error}
+
+
+
+
+ );
}
if (!team) {
- return Team not found
;
+ return (
+
+
🔍
+
Team not found
+
+
+
+
+ );
}
return (
-
+
←
-
{team.name}
-
{team.code}
-
00:00
+
+
{team.name}
+
Team Code: {team.code}
+
-
-
- Add Users
-
+
+
Team Members
-
- {teamMembers.map((member) => (
-
- {member.username} {member.id === session?.user?.id && "(You)"}
-
- ))}
-
-
-
+
+ {teamMembers.length > 0 ? (
+
+ {teamMembers.map((member) => (
+
+
👤
+
+
+ {member.username}
+ {member.id === session?.user?.id && " (You)"}
+
+
+
+ ))}
-
+ ) : (
+
No team members found
+ )}
+
+
-
-