From af78d8e18a95bb17a04a81e1805afc7bcd4b2816 Mon Sep 17 00:00:00 2001 From: suzinxix Date: Wed, 15 Mar 2023 01:28:25 +0900 Subject: [PATCH 1/2] [#86] fix: fix GET error --- bowwowcare/src/context/ThemeProvider.js | 14 +++++++++----- bowwowcare/src/utils/isLogin.js | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 bowwowcare/src/utils/isLogin.js 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 From ce377c89ce954fb86068dfdd429f044cdf6e44b8 Mon Sep 17 00:00:00 2001 From: suzinxix Date: Wed, 15 Mar 2023 13:44:56 +0900 Subject: [PATCH 2/2] [#86] fix: fix GET error --- bowwowcare/src/views/HomePage/HomePage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 (