File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change 11import { getKakaoLogin } from '@/apis/auth' ;
2+ import Loading from '@/components/loading/Loading' ;
23import { useAuthStore } from '@/store/authStore' ;
3- import React , { useEffect } from 'react' ;
4+ import { useEffect } from 'react' ;
45import { useNavigate } from 'react-router' ;
56
67function 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
2532export default KaKaoRedirection ;
You can’t perform that action at this time.
0 commit comments