
--- src/pages/main/MainSelect.jsx
+++ src/pages/main/MainSelect.jsx
... | ... | @@ -1,9 +1,12 @@ |
1 | 1 |
import React, { useEffect } from "react"; |
2 | 2 |
import "./MainParent.css"; |
3 | 3 |
import { useNavigate } from "react-router-dom"; |
4 |
+import { useCookies } from "react-cookie"; |
|
4 | 5 |
import axios from "axios"; |
5 | 6 |
|
6 | 7 |
const MainSelect = () => { |
8 |
+ const [cookies, setCookie, removeCookie] = useCookies(["loggedIn"]); |
|
9 |
+ |
|
7 | 10 |
const navigate = useNavigate(); |
8 | 11 |
const fetchData = async () => { |
9 | 12 |
try { |
... | ... | @@ -26,8 +29,12 @@ |
26 | 29 |
} |
27 | 30 |
}; |
28 | 31 |
useEffect(() => { |
29 |
- fetchData(); |
|
30 |
- }, []); |
|
32 |
+ if (!cookies.loggedIn) { |
|
33 |
+ navigate("/login"); |
|
34 |
+ } else { |
|
35 |
+ fetchData(); |
|
36 |
+ } |
|
37 |
+ }, [cookies.loggedIn]); |
|
31 | 38 |
|
32 | 39 |
return <div>loading...</div>; |
33 | 40 |
}; |
--- src/pages/main/mainp.jsx
+++ src/pages/main/mainp.jsx
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 |
const [cookies, setCookie, removeCookie] = useCookies(["loggedIn"]); |
11 | 11 |
const navigate = useNavigate(); |
12 | 12 |
const [currentStep, setCurrentStep] = useState(1); |
13 |
+ |
|
13 | 14 |
const [abilities, setAbilities] = useState([ |
14 | 15 |
{ name: "어휘", level: 50 }, |
15 | 16 |
{ name: "문장", level: 50 }, |
... | ... | @@ -40,12 +41,14 @@ |
40 | 41 |
}; |
41 | 42 |
|
42 | 43 |
const fetchData = async () => { |
44 |
+ |
|
43 | 45 |
try { |
44 | 46 |
const response = await axios.get(`http://165.229.169.127:8080/rating`, { |
45 | 47 |
withCredentials: true, |
46 | 48 |
}); |
47 | 49 |
const responseData = response.data.data; // response.data는 이미 JavaScript 객체로 사용 가능합니다. |
48 | 50 |
const role = responseData.role; |
51 |
+ |
|
49 | 52 |
if (role == "parent") { |
50 | 53 |
navigate("/mainParent"); |
51 | 54 |
} else { |
... | ... | @@ -62,6 +65,13 @@ |
62 | 65 |
useEffect(() => { |
63 | 66 |
fetchData(); |
64 | 67 |
}, []); |
68 |
+ |
|
69 |
+ useEffect(() => { |
|
70 |
+ if (!cookies["loggedIn"]) { |
|
71 |
+ navigate("/login"); |
|
72 |
+ } |
|
73 |
+ }, [cookies["loggedIn"]]); |
|
74 |
+ |
|
65 | 75 |
// 사용자 입력을 저장할 state 초기화 |
66 | 76 |
const [comment, setComment] = useState( |
67 | 77 |
"어서와~ 꿈 속 우주공간은 처음이지? 여행하고 싶은 행성을 골라봐~" |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?