Skip to content

Commit e712648

Browse files
committed
feat: 카카오 로그인 구현
1 parent 0675f5a commit e712648

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import { getKakaoLogin } from '@/apis/auth';
2+
import Loading from '@/components/loading/Loading';
23
import { useAuthStore } from '@/store/authStore';
3-
import React, { useEffect } from 'react';
4+
import { useEffect } from 'react';
45
import { useNavigate } from 'react-router';
56

67
function KaKaoRedirection() {
78
const navigate = useNavigate();
8-
const code = new URL(window.location.href).searchParams.get('code');
9-
const { setAccessToken } = useAuthStore;
9+
const kakaoCode = new URL(window.location.href).searchParams.get('code');
10+
const { setAccessToken } = useAuthStore();
1011

1112
const handleKaKaoLogin = async () => {
1213
try {
13-
const data = await getKakaoLogin(code as string);
14-
// 토큰 저장하기
15-
navigate('/home');
16-
} catch (error) {}
14+
const { code, data } = await getKakaoLogin(kakaoCode as string);
15+
if (code === 200) {
16+
setAccessToken(data.accessToken);
17+
navigate('/home');
18+
} else {
19+
throw new Error('로그인 에러');
20+
}
21+
} catch (error) {
22+
console.error('로그인 에러가 발생했습니다.');
23+
}
1724
};
1825

1926
useEffect(() => {
2027
handleKaKaoLogin();
2128
}, []);
22-
return <div>KaKaoRedirection</div>;
29+
return <Loading />;
2330
}
2431

2532
export default KaKaoRedirection;

0 commit comments

Comments
 (0)