FIX OF ALL ISSUES WITH LOG IN PAGE. EVERYTHING TO THE POINT OF TESTING THE MAP WORKS SO FAR.

This commit is contained in:
bobbert committed 2025-03-15 00:22:47 +00:00
1 parent 84f010cb87
commit c79a9636a7
10 files changed
+228 -233

No files matched your search

+16 -5
View File
@@ -15,8 +15,8 @@ export default function CreateTeam() {
useEffect(() => {
if (status === "authenticated") {
if (session.user.teamId) {
router.push(`/team/${session.user.teamId}`);
if (session?.user?.teamId) {
router.push(`/${session.user.teamId}`);
} else {
setIsLoading(false);
}
@@ -31,12 +31,17 @@ export default function CreateTeam() {
setError("");
try {
// Add a check to ensure session is valid
if (status !== "authenticated") {
throw new Error("You must be logged in to create a team");
}
const response = await fetch("/api/teams", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
credentials: "include", // Important: include credentials
body: JSON.stringify({ name: teamName }),
});
@@ -46,12 +51,18 @@ export default function CreateTeam() {
throw new Error(data.error || "Failed to create team");
}
// 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
// Force a session refresh to update the session with the new teamId
await fetch("/api/auth/session", {
method: "GET",
credentials: "include",
});
// Hard navigation to make sure we're going to the right page
window.location.href = `/${data.teamId}`;
} catch (err) {
console.error("Team creation error:", err);
setError(err.message);
setIsLoading(false);
}