Skip to content

Commit 3c7806d

Browse files
fixed bug
1 parent 6140254 commit 3c7806d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

auth.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,23 @@ async function checkUserSession() {
5757
const { data, error } = await supabase.auth.getSession();
5858

5959
// If there is no active session, or an error, redirect to login
60-
if (!data.session) {
61-
console.log("No active session found. Redirecting to login page.");
62-
window.location.href = "login.html";
63-
} else {
64-
console.log("Active session found. User is logged in.");
65-
// Optional: you can add code here to show user-specific content
66-
}
60+
async function checkUserSession() {
61+
const { data, error } = await supabase.auth.getSession();
62+
63+
// Get the current page
64+
const currentPage = window.location.pathname.split("/").pop();
65+
66+
if (!data.session && currentPage !== "login.html" && currentPage !== "signup.html") {
67+
console.log("No active session found. Redirecting to login page.");
68+
window.location.href = "login.html";
69+
} else if (data.session && (currentPage === "login.html" || currentPage === "signup.html")) {
70+
console.log("User already logged in. Redirecting to dashboard.");
71+
window.location.href = "index.html";
72+
} else {
73+
console.log("Session valid or on correct page. No redirect needed.");
74+
}
75+
}
76+
6777
}
6878

6979
// 2. Handle Logout

0 commit comments

Comments
 (0)