Skip to content

Commit

Permalink
chore: 협업을 위한 카카오 로그인 코드 수정 [#60]
Browse files Browse the repository at this point in the history
  • Loading branch information
j2h30728 committed Apr 18, 2024
1 parent ed40c04 commit 5766244
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
4 changes: 4 additions & 0 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const BottomBar = () => {
);
};
const Layout = ({ top, children }: { top?: TopBar; children: ReactNode }) => {
const navigate = useNavigate();
if (!localStorage.getItem('token')) {
navigate(ROUTE_PATH.INTRO);
}
return (
<S.Container>
{top && <TopBar {...top} />}
Expand Down
39 changes: 2 additions & 37 deletions src/pages/KakaoLogIn.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
import axios from 'axios';
import QueryString from 'qs';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import ROUTE_PATH from '../router/constants';

const {
VITE_KAKAO_REST_API_KEY,
VITE_KAKAO_REDIRECT_URI,
VITE_KAKAO_CLIENT_SECRET,
} = import.meta.env;

const KakaoLogIn = () => {
const navigate = useNavigate();
useEffect(() => {
const code = new URL(window.location.href).searchParams.get('code');
const code = new URL(window.location.href).searchParams.get('code');

const getToken = async () => {
const payload = QueryString.stringify({
grant_type: 'authorization_code',
client_id: VITE_KAKAO_REST_API_KEY,
redirect_uri: VITE_KAKAO_REDIRECT_URI,
code: code,
client_secret: VITE_KAKAO_CLIENT_SECRET,
});
try {
const response = await axios.post(
'https://kauth.kakao.com/oauth/token',
payload
);
// response.data 에서 access_token 과 refresh_token이 존재함
console.log(response);
navigate(ROUTE_PATH.REGISTER_PET);
} catch (error) {
console.error(error);
}
};
getToken();
}, [navigate]);
console.log(code);

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/router/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ROUTE_PATH = {
ROOT: '/',
HOME: '',
INTRO: 'intro',
INTRO: '/intro',
KAKAO_LOGIN: '/oauth/kakao/callback',
REGISTER_PET: '/register/pet',
REGISTER_PEOPLE: '/register/people',
Expand Down

0 comments on commit 5766244

Please sign in to comment.