mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed issue with login page.
This commit is contained in:
1 parent
11fc5c8b3d
commit
84f010cb87
6 files changed
+153
-30
No files matched your search
@@ -12,13 +12,12 @@ export default function TeamSelection() {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
// Clear any leftover team data cache from previous teams
|
||||
// Clear any leftover team data
|
||||
localStorage.removeItem("teamData");
|
||||
sessionStorage.removeItem("teamData");
|
||||
localStorage.removeItem("userLeftTeam");
|
||||
|
||||
if (status === "authenticated") {
|
||||
// Always verify team status with a fresh API call to avoid stale session data
|
||||
fetch(`/api/user?_t=${Date.now()}`, {
|
||||
headers: {
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
@@ -28,20 +27,12 @@ export default function TeamSelection() {
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((userData) => {
|
||||
console.log("User data:", userData); // Debug user data
|
||||
|
||||
// Check if user is an admin first
|
||||
console.log("User data:", userData);
|
||||
if (userData.role === "admin") {
|
||||
// Redirect admin to admin dashboard with correct path
|
||||
router.push("/admin"); // Changed from /admin-dashboard to /admin
|
||||
router.push("/admin");
|
||||
} else if (userData.teamId) {
|
||||
// Only attempt to construct URL if teamId is valid
|
||||
if (userData.teamId && !isNaN(parseInt(userData.teamId))) {
|
||||
window.location.href = `/${userData.teamId}`;
|
||||
} else {
|
||||
console.error("Invalid teamId received:", userData.teamId);
|
||||
setIsLoading(false);
|
||||
}
|
||||
// Use router.push for client-side navigation
|
||||
router.push(`/${userData.teamId}`);
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -53,10 +44,9 @@ export default function TeamSelection() {
|
||||
} else if (status === "unauthenticated") {
|
||||
router.push("/login");
|
||||
} else {
|
||||
// Still loading session
|
||||
setIsLoading(true);
|
||||
}
|
||||
}, [status, session, router]);
|
||||
}, [status, router]);
|
||||
|
||||
const handleJoinTeam = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in new issue
Block a user