diff --git a/src/hooks/queries/usePostKakao.tsx b/src/hooks/queries/usePostKakao.tsx index 2878875..8bacdc5 100644 --- a/src/hooks/queries/usePostKakao.tsx +++ b/src/hooks/queries/usePostKakao.tsx @@ -18,16 +18,10 @@ const usePostKakao = () => { const res = await kakao.postKakaoLogin({ kakaoToken: accessToken, fcmToken: '0' }); const data: KakaoLoginResponseType = res.data; console.log('data', data); - setKakaoResponse({ - userId: data.data.userId, - accessToken: data.data.accessToken, - isAlreadyUser: data.data.isAlreadyUser, - refreshToken: data.data.refreshToken, - nickname: data.data.nickname, - }); - console.log('응답이 왔나요?', kakaoResponse); - localStorage.setItem('ACCESS_TOKEN', data.data.accessToken); - localStorage.setItem('REFRESH_TOKEN', data.data.refreshToken); + setKakaoResponse(data.data); + // console.log('응답이 왔나요?', kakaoResponse); + // localStorage.setItem('ACCESS_TOKEN', data.data.accessToken); + // localStorage.setItem('REFRESH_TOKEN', data.data.refreshToken); } catch (err) { setKakaoError(err as AxiosError); console.log('에러 발생', err); diff --git a/src/pages/KakaoLoginPage.tsx b/src/pages/KakaoLoginPage.tsx index 0a3953c..d8cb240 100644 --- a/src/pages/KakaoLoginPage.tsx +++ b/src/pages/KakaoLoginPage.tsx @@ -10,40 +10,36 @@ const KakaoLoginPage = () => { // let code = new URL(window.location.href).searchParams.get('code'); // console.log('CODE', code); - const { kakaoResponse, kakaoError, kakaoLoading, postKakao } = usePostKakao(); + const { kakaoResponse, kakaoLoading, postKakao } = usePostKakao(); - const handlePostKakao = async (code: string) => { + const fetchLogin = async () => { try { - await postKakao(code); - if (!kakaoError && !kakaoLoading && kakaoResponse) { - console.log('이동 전 콘솔 확인', kakaoResponse); - if (kakaoResponse.isAlreadyUser) { - navigate('/delete'); - } else { - navigate('/unregistered'); - } + const res = await useGetToken(); + if (res) { + const token = res.data.access_token; + + // localStorage.setItem('ACCESS_TOKEN', JSON.stringify(token)); + // await handlePostKakao(token); + await postKakao(token); } - } catch (error) { - console.log('ERROR', error); - navigate('/unregistered'); + } catch (err) { + console.log(err); } }; useEffect(() => { - const fetchLogin = async () => { - try { - const res = await useGetToken(); - if (res) { - const token = res.data.access_token; - // localStorage.setItem('ACCESS_TOKEN', JSON.stringify(token)); - await handlePostKakao(token); - } - } catch (err) { - console.log(err); - } - }; fetchLogin(); - }, []); + }, [fetchLogin]); + + useEffect(() => { + if (!kakaoLoading && kakaoResponse) { + if (kakaoResponse.isAlreadyUser) { + navigate('/delete'); + } else { + navigate('/unregistered'); + } + } + }, [kakaoLoading, kakaoResponse, navigate]); return <>; };