Skip to content

Commit edede06

Browse files
committed
fix: 로그인 안되는 문제 해결 1차
1 parent 2b59eb3 commit edede06

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/components/button/KakaoLoginButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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 kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=3e5cfa29037d1bd11eb5448f9b298bfe&redirect_uri=https://localhost:5173/kakao-login&response_type=code`;
33

44
const handleClick = () => {
55
window.location.href = kakaoURL;
@@ -9,7 +9,7 @@ const KakaoLoginButton = () => {
99
<button
1010
type="button"
1111
onClick={handleClick}
12-
className="flex justify-center items-center bg-[#F9E622] hover:opacity-80 rounded-lg w-[320px] h-[56px] font-bold text-black"
12+
className="flex h-[56px] w-[320px] items-center justify-center rounded-lg bg-[#F9E622] font-bold text-black hover:opacity-80"
1313
>
1414
카카오로 시작하기
1515
</button>

src/pages/KaKaoLogin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ 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) {
1717
console.error("카카오 로그인에 실패했습니다.");
1818
}

src/store/useAuthStore.ts

Lines changed: 12 additions & 7 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

@@ -17,21 +17,26 @@ const useAuthStore = create(
1717
login: async (code: string) => {
1818
try {
1919
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-
}
20+
set({
21+
isLoggedIn: true,
22+
accessToken: res.data as string
23+
});
24+
return {
25+
ok: true
26+
};
2627
} catch (error) {
2728
console.error("Error during login:", error);
29+
return {
30+
ok: false
31+
};
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)