Expected to work without errors, but getting these following errors in the console:
1Checking session... [script.js:125:13](https://it-club-3qbsuaqhv-ahmad-zarirs-projects.vercel.app/static/js/script.js)23Cookie “_vercel_sso_nonce” has been rejected because it is in a cross-site context and its “SameSite” is “Lax” or “Strict”. 2 [check_session](https://it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app/check_session)45Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app/check_session. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 401.67Error checking session: TypeError: NetworkError when attempting to fetch resource. [script.js:147:17](https://it-club-3qbsuaqhv-ahmad-zarirs-projects.vercel.app/static/js/script.js)89XHROPTIONShttps://it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app/loginCORS Missing Allow Origin1011Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 401.1213Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app/login. (Reason: CORS request did not succeed). Status code: (null).14
code for my static/js:
1const IP = 'it-club-nhglwo0kg-ahmad-zarirs-projects.vercel.app';2document.addEventListener("DOMContentLoaded", () => {3 initializePage();4});56// Initialize the page elements and event listeners7function initializePage() {8 const showPasswordCheckbox = document.getElementById("show-password");9 const emailField = document.getElementById("email"); // Changed from "username" to "email"10 const passwordField = document.getElementById("password");1112 // Ensure the password checkbox is unchecked by default13 showPasswordCheckbox.checked = false;1415 // Toggle password visibility16 showPasswordCheckbox.addEventListener("change", () => {17 passwordField.type = showPasswordCheckbox.checked ? "text" : "password";18 });1920 // Handle Enter key in the email field21 emailField.addEventListener("keypress", (e) => {22 if (e.key === "Enter") {23 passwordField.focus();24 }25 });2627 // Handle Enter key in the password field28 passwordField.addEventListener("keypress", (e) => {29 if (e.key === "Enter") {30 login();31 }32 });3334 // Check for an active session when the page loads35 checkSession();36}3738// Display the loading screen39function showLoading() {40 const loadingScreen = document.getElementById("loading-screen");41 if (loadingScreen) {42 loadingScreen.style.display = "flex";43 }44}4546// Hide the loading screen47function hideLoading() {48 const loadingScreen = document.getElementById("loading-screen");49 if (loadingScreen) {50 loadingScreen.style.display = "none";51 }52}5354// Handle user login55async function login() {56 const email = document.getElementById("email").value; // Changed from "username" to "email"57 const password = document.getElementById("password").value;58 const message = document.getElementById("message");5960 if (!email || !password) {61 displayMessage("Please fill in all fields", "red");62 return;63 }6465 showLoading();6667 try {68 const response = await fetch(`http://${IP}/login`, {69 method: "POST",70 headers: { "Content-Type": "application/json" },71 body: JSON.stringify({ email, password }), // Send email instead of username72 credentials: "include",73 });7475 if (!response.ok) {76 throw new Error("Failed to authenticate");77 }7879 const result = await response.json();8081 if (result.success) {82 await loadUserPage(result.user);83 displayMessage("Login successful!", "green");84 } else {85 displayMessage("Invalid email or password", "red");86 }87 } catch (error) {88 displayMessage("An error occurred. Please try again later", "red");89 } finally {90 hideLoading();91 }92}9394async function loadUserPage(user) {95 console.log("Loading user page for:", user);96 showLoading();9798 try {99 const response = await fetch(`http://${IP}/user_page`, {100 method: "GET",101 credentials: "include",102 });103104 if (!response.ok) {105 console.error("Failed to load user page", response);106 throw new Error("Failed to load user page");107 }108109 const pageContent = await response.text();110 document.body.innerHTML = pageContent; // Replace body content with user page111112 // Ensure user data is inserted after content is loaded113 console.log("Populating user data into the page...");114 document.getElementById("user-name").textContent = user.name;115 document.getElementById("user-id").textContent = user.id;116 } catch (error) {117 console.error("Error loading user page:", error);118 } finally {119 hideLoading();120 }121}122123async function checkSession() {124 console.log("Checking session..."); // Add logging here125 showLoading();126127 try {128 const response = await fetch(`http://${IP}/check_session`, {129 method: "GET",130 credentials: "include",131 });132133 const result = await response.json();134 console.log("Session check result:", result); // Log the session check result135136 if (result.success) {137 console.log("Session active, loading user page...");138 // If session is active, load the user page139 await loadUserPage(result.user);140 } else {141 console.warn("No active session. Displaying login page.");142 displayMessage("Please log in.", "red");143 hideLoading();144 }145 } catch (error) {146 console.error("Error checking session:", error);147 } finally {148 hideLoading();149 }150}151152// Log out the user and clear session data153async function logout() {154 showLoading();155156 try {157 await fetch(`http://${IP}logout`, {158 method: "POST",159 credentials: "include",160 });161 localStorage.removeItem("user");162 location.reload();163 } catch (error) {164 console.error("Error logging out:", error);165 } finally {166 hideLoading();167 }168}169170// Display a message to the user171function displayMessage(text, color) {172 const message = document.getElementById("message");173 if (message) {174 message.style.color = color;175 message.textContent = text;176 }177}
https://it-club-3qbsuaqhv-ahmad-zarirs-projects.vercel.app/