File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed
Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments