Skip to content

Commit 6bb02f8

Browse files
committed
[FIX] /api/user/me API 요청 조건 수정
1 parent 6b49c80 commit 6bb02f8

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/pages/HomePage.jsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,32 @@ export default function HomePage() {
2929

3030

3131
// 컴포넌트 마운트 시와 쿠키 변경 시 로그인 상태 체크
32-
useEffect(() => {
33-
const checkLoginStatus = async () => {
34-
try {
35-
// 먼저 로그인 상태 확인
32+
const checkLoginStatus = async () => {
33+
try {
34+
// 로그인 상태일 때만 API 호출
35+
if (isLoggedIn) {
3636
const response = await fetch(`${import.meta.env.VITE_SERVER_URL}/api/user/me`, {
3737
credentials: 'include'
3838
});
3939

4040
if (response.ok) {
4141
const userData = await response.json();
4242
setUser(userData);
43-
setIsLoggedIn(true); // 응답이 성공하면 로그인 상태로 설정
44-
4543
} else {
4644
setUser(null);
4745
setIsLoggedIn(false);
4846
}
49-
} catch (error) {
50-
console.error('Failed to check login status:', error);
51-
setUser(null);
52-
setIsLoggedIn(false);
5347
}
54-
};
55-
56-
checkLoginStatus();
57-
58-
59-
}, []);
48+
} catch (error) {
49+
console.error('Failed to check login status:', error);
50+
setUser(null);
51+
setIsLoggedIn(false);
52+
}
53+
};
54+
55+
useEffect(() => {
56+
checkLoginStatus();
57+
}, [isLoggedIn]); // isLoggedIn이 변경될 때마다 실행
6058

6159
useEffect(() => {
6260
if (!isLoggedIn && activeSort === "my-reservations") {

0 commit comments

Comments
 (0)