Browse Source

Change to using a note in localStorage to check if logged in.

Lee Morgan 1 năm trước cách đây
mục cha
commit
e957c788a9
2 tập tin đã thay đổi với 6 bổ sung18 xóa
  1. 5 18
      views/index.js
  2. 1 0
      views/js/pages/login.js

+ 5 - 18
views/index.js

@@ -9,7 +9,6 @@ import editWorkoutPage from "./js/pages/editWorkout.js";
 const notifier = document.getElementById("notifier");
 const pageElements = document.querySelectorAll(".page");
 
-
 window.notify = (type, message)=>{
     notifier.className = "";
     notifier.classList.add(type);
@@ -38,23 +37,11 @@ window.changePage = (page, data)=>{
     }
 }
 
-fetch("/user", {
-    method: "GET",
-    header: {
-        "Content-Type": "application/json"
-    }
-})
-    .then(r=>r.json())
-    .then((response)=>{
-        if(response.error){
-            changePage("login");
-        }else{
-            changePage("home");
-        }
-    })
-    .catch((err)=>{
-        changePage("login");
-    });
+if(localStorage.getItem("loggedIn") === "true"){
+    changePage("home");
+}else{
+    changePage("login");
+}
 
 if("serviceWorker" in navigator){
     window.addEventListener("load", ()=>{

+ 1 - 0
views/js/pages/login.js

@@ -35,6 +35,7 @@ export default {
                     if(response.error){
                         notify("error", response.error.message);
                     }else{
+                        localStorage.setItem("loggedIn", "true");
                         changePage("home", response);
                     }
                 })