Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKRF-132 로그인 api 서버에 요청 #18

Merged
merged 11 commits into from
Oct 25, 2023
10 changes: 10 additions & 0 deletions src/apis/auth/kakaoLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { User } from '@/types/user';

import { END_POINTS } from '@constants/api';

import { axiosClient } from '../axiosClient';

export const kakaoLogin = async (code: string) => {
const { data } = await axiosClient.post<User>(END_POINTS.KAKAO_LOGIN, { code });
return data;
};
12 changes: 12 additions & 0 deletions src/apis/axiosClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from 'axios';

import { NETWORK_TIMEOUT, SPACECLUB_BASE_URL } from '@constants/api';

export const axiosClient = axios.create({
baseURL: SPACECLUB_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
withCredentials: true,
timeout: NETWORK_TIMEOUT,
});
9 changes: 9 additions & 0 deletions src/constants/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const SPACECLUB_BASE_URL = 'https://spaceclub.site';

const NETWORK_TIMEOUT = 10000;

const END_POINTS = {
KAKAO_LOGIN: '/login/kakao',
};

export { SPACECLUB_BASE_URL, NETWORK_TIMEOUT, END_POINTS };
13 changes: 12 additions & 1 deletion src/pages/OauthRedirectPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { kakaoLogin } from '@/apis/auth/kakaoLogin';

import { useEffect } from 'react';

const OauthRedirectPage = () => {
const authCode = new URL(window.location.href).searchParams.get('code');

useEffect(() => {}, []);
useEffect(() => {
if (!authCode) {
throw new Error('인증 코드가 없습니다.');
}

kakaoLogin(authCode).then(({ accessToken }) => {
localStorage.setItem('accessToken', accessToken);
window.location.href = '/';
});
});

return <div>OauthRedirectPage</div>;
};
Expand Down
5 changes: 5 additions & 0 deletions src/types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface User {
accessToken: string;
}

export { User };
28 changes: 14 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"jsx": "react-jsx",
"allowJs": true,
"baseUrl": "./",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@components/*": ["src/components/*"],
"@type/*": ["src/types/*"],
"@hooks/*": ["src/hooks/*"],
"@pages/*": ["src/pages/*"],
"@styles/*": ["src/styles/*"],
"@constants/*": ["src/constants/*"],
"@assets/*": ["src/assets/*"],
"@api/*": ["src/api/*"],
"@router/*": ["src/router/*"],
"@store/*": ["src/store/*"],
"@utils/*": ["src/utils/*"]
"@/*": ["./src/*"],
"@components/*": ["./src/components/*"],
"@types/*": ["./src/types/*"],
"@hooks/*": ["./src/hooks/*"],
"@pages/*": ["./src/pages/*"],
"@styles/*": ["./src/styles/*"],
"@constants/*": ["./src/constants/*"],
"@assets/*": ["./src/assets/*"],
"@api/*": ["./src/api/*"],
"@router/*": ["./src/router/*"],
"@store/*": ["./src/store/*"],
"@utils/*": ["./src/utils/*"]
},
"jsxImportSource": "@emotion/react",
"allowSyntheticDefaultImports": true
},
"exclude": ["node_modules"],
"include": ["src", "**/*.ts", "**/*.tsx"]
"include": ["**/*.ts", "**/*.tsx"]
}
Loading