Skip to content

Commit 89b686b

Browse files
authored
Merge pull request #403 from TripInfoWeb/dev
fix: Release: v1.0.3 build 문제 수정
2 parents 87b0581 + 9488aaf commit 89b686b

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/containers/auth/AuthNaverContainer.tsx

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,50 @@
33
import AuthLoading from "@/components/auth/AuthLoading";
44
import useAuthStore from "@/store/authStore";
55
import { useRouter } from "next/navigation";
6+
import { useEffect } from "react";
67

78
const AuthNaverContainer = () => {
89
const router = useRouter();
910
const authStore = useAuthStore();
1011

11-
const url = new URL(window.location.href);
12-
const naverLogin = async () => {
13-
try {
14-
const response = await fetch(
15-
`/api/auth/naver/getToken?code=${url.searchParams.get("code")}`,
16-
{
17-
method: "GET",
18-
headers: {
19-
"Content-Type": "application/json",
20-
},
21-
cache: "no-store",
22-
credentials: "include",
23-
},
24-
);
25-
26-
27-
if (!response.ok) {
28-
throw new Error("Failed to login");
12+
useEffect(() => {
13+
const url = new URL(window.location.href);
14+
15+
const naverLogin = async () => {
16+
try {
17+
const response = await fetch(
18+
`/api/auth/naver/getToken?code=${url.searchParams.get("code")}`,
19+
{
20+
method: "GET",
21+
headers: {
22+
"Content-Type": "application/json",
23+
},
24+
cache: "no-store",
25+
credentials: "include",
26+
}
27+
);
28+
29+
if (!response.ok) {
30+
throw new Error("Failed to login");
31+
}
32+
33+
// 액세스 토큰을 이용해서 사용자 정보 조회
34+
const userDataResponse = await fetch("/api/auth/user");
35+
if (userDataResponse.status === 200) {
36+
const userData = await userDataResponse.json();
37+
authStore.setUser(userData);
38+
router.push("/");
39+
} else {
40+
throw new Error("Failed to fetch user data");
41+
}
42+
} catch (error) {
43+
console.error("로그인 실패", error);
44+
router.push("/auth/signin");
2945
}
46+
};
3047

31-
// 액세스 토큰을 이용해서 사용자 정보 조회
32-
const userDataResponse = await fetch("/api/auth/user");
33-
if (userDataResponse.status == 200) {
34-
const userData = await userDataResponse.json();
35-
authStore.setUser(userData);
36-
router.push("/");
37-
} else {
38-
throw new Error("Failed to fetch user data");
39-
}
40-
} catch (error) {
41-
console.error("로그인 실패", error);
42-
router.push("/auth/signin");
43-
}
44-
};
45-
46-
naverLogin();
48+
naverLogin();
49+
}, []);
4750

4851
return <AuthLoading />;
4952
};

0 commit comments

Comments
 (0)