Skip to content

Commit 5d5d33a

Browse files
authored
Merge pull request #210 from MBTips/fix/로그인-안되는-문제-해결-1차
fix: 로그인 안되는 문제 해결 1차
2 parents fd76ef2 + 57049e5 commit 5d5d33a

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/components/button/KakaoLoginButton.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const KakaoLoginButton = () => {
2-
const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${import.meta.env.VITE_KAKAO_REST_API_KEY}&redirect_uri=${import.meta.env.VITE_KAKAO_REDIRECT_URI}&response_type=code`;
2+
const kakaoRestApiKey = import.meta.env.VITE_KAKAO_REST_API_KEY;
3+
const kakaoRedirectUrl = import.meta.env.VITE_KAKAO_REDIRECT_URI;
4+
5+
const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${kakaoRestApiKey}&redirect_uri=${kakaoRedirectUrl}&response_type=code`;
36

47
const handleClick = () => {
58
window.location.href = kakaoURL;
@@ -9,7 +12,7 @@ const KakaoLoginButton = () => {
912
<button
1013
type="button"
1114
onClick={handleClick}
12-
className="flex justify-center items-center bg-[#F9E622] hover:opacity-80 rounded-lg w-[320px] h-[56px] font-bold text-black"
15+
className="flex h-[56px] w-[320px] items-center justify-center rounded-lg bg-[#F9E622] font-bold text-black hover:opacity-80"
1316
>
1417
카카오로 시작하기
1518
</button>

src/pages/KaKaoLogin.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const KaKaoLogin = () => {
1111
const getTokenAndLogin = async () => {
1212
if (typeof code === "string") {
1313
try {
14-
await login(code);
15-
navigate("/");
14+
const res = await login(code);
15+
if (res.ok) navigate("/");
1616
} catch (err) {
17-
console.error("카카오 로그인에 실패했습니다.");
17+
navigate("/error");
1818
}
1919
}
2020
};

src/store/useAuthStore.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import instance from "@/api/axios";
55
interface AuthStore {
66
isLoggedIn: boolean;
77
accessToken: string | null;
8-
login: (code: string) => Promise<void>;
8+
login: (code: string) => Promise<{ ok: boolean }>;
99
logout: () => void;
1010
}
1111

@@ -16,22 +16,27 @@ const useAuthStore = create(
1616
accessToken: null,
1717
login: async (code: string) => {
1818
try {
19-
const res = await instance.get(`/api/kakao/login?code=${code}`);
20-
if (res.data) {
21-
set({
22-
isLoggedIn: true,
23-
accessToken: res.data as string
24-
});
25-
}
19+
const res = await instance.get(
20+
`/api/kakao/login?code=${code}`
21+
// + "&redirectUrl=https://localhost:5173/kakao-login"
22+
);
23+
set({
24+
isLoggedIn: true,
25+
accessToken: res.data as string
26+
});
27+
return {
28+
ok: true
29+
};
2630
} catch (error) {
27-
console.error("Error during login:", error);
31+
throw error;
2832
}
2933
},
3034
logout: () => {
3135
set({
3236
isLoggedIn: false,
3337
accessToken: null
3438
});
39+
return { ok: true };
3540
}
3641
}),
3742
{

0 commit comments

Comments
 (0)