diff --git a/bowwowcare/src/context/ThemeProvider.js b/bowwowcare/src/context/ThemeProvider.js index a5bf8e1..2b61c65 100644 --- a/bowwowcare/src/context/ThemeProvider.js +++ b/bowwowcare/src/context/ThemeProvider.js @@ -1,5 +1,6 @@ import { createContext, useState, useEffect } from "react"; import userService from "../services/user.service"; +import { isLogin } from "../utils/isLogin"; export const ThemeContext = createContext({}); @@ -8,14 +9,17 @@ function ThemeProvider({ children }) { const [myTheme, setMyTheme] = useState(0); const [ThemeMode, setThemeMode] = useState(theme[0]); + useEffect(() => { - userService.getUserBoard().then((response) => { - if(response.status === 200) { - const user = response.data; - setMyTheme(user.theme); + if(isLogin()){ + userService.getUserBoard().then((response) => { + if(response.status === 200) { + const user = response.data; + setMyTheme(user.theme); + } } + ).catch((e) => {console.log(e.response.data)}) } - ).catch((e) => {console.log(e.response.data)}) },[]); useEffect(() => { diff --git a/bowwowcare/src/utils/isLogin.js b/bowwowcare/src/utils/isLogin.js new file mode 100644 index 0000000..b56fb39 --- /dev/null +++ b/bowwowcare/src/utils/isLogin.js @@ -0,0 +1 @@ +export const isLogin = () => !!localStorage.getItem("user"); \ No newline at end of file diff --git a/bowwowcare/src/views/HomePage/HomePage.js b/bowwowcare/src/views/HomePage/HomePage.js index c5916b9..400ff55 100644 --- a/bowwowcare/src/views/HomePage/HomePage.js +++ b/bowwowcare/src/views/HomePage/HomePage.js @@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom"; import axios from "axios"; import { API_URL } from "../../Config"; import authHeader from "../../services/auth-header"; +import { isLogin } from "../../utils/isLogin"; import Header from "../../components/Header"; import PetList from "./PetList/PetList"; @@ -39,7 +40,7 @@ function HomePage() { }; useEffect(() => { - getPetList(); + isLogin() && getPetList(); }, []); return (