diff --git a/frontend/build/asset-manifest.json b/frontend/build/asset-manifest.json deleted file mode 100644 index 6cb8b4e..0000000 --- a/frontend/build/asset-manifest.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "files": { - "main.css": "/static/css/main.edab73f6.css", - "main.js": "/static/js/main.06c85235.js", - "static/css/216.3fa19541.chunk.css": "/static/css/216.3fa19541.chunk.css", - "static/js/216.ea565ff2.chunk.js": "/static/js/216.ea565ff2.chunk.js", - "static/js/592.bf6ca574.chunk.js": "/static/js/592.bf6ca574.chunk.js", - "static/js/603.94be1680.chunk.js": "/static/js/603.94be1680.chunk.js", - "service-worker.js": "/service-worker.js", - "index.html": "/index.html", - "main.edab73f6.css.map": "/static/css/main.edab73f6.css.map", - "main.06c85235.js.map": "/static/js/main.06c85235.js.map", - "216.3fa19541.chunk.css.map": "/static/css/216.3fa19541.chunk.css.map", - "216.ea565ff2.chunk.js.map": "/static/js/216.ea565ff2.chunk.js.map", - "592.bf6ca574.chunk.js.map": "/static/js/592.bf6ca574.chunk.js.map", - "603.94be1680.chunk.js.map": "/static/js/603.94be1680.chunk.js.map" - }, - "entrypoints": [ - "static/css/main.edab73f6.css", - "static/js/main.06c85235.js" - ] -} \ No newline at end of file diff --git a/frontend/build/favicon.ico b/frontend/build/favicon.ico deleted file mode 100644 index eed6d84..0000000 Binary files a/frontend/build/favicon.ico and /dev/null differ diff --git a/frontend/build/index.html b/frontend/build/index.html deleted file mode 100644 index 515c5bb..0000000 --- a/frontend/build/index.html +++ /dev/null @@ -1 +0,0 @@ -TOEIC
\ No newline at end of file diff --git a/frontend/build/logo192.png b/frontend/build/logo192.png deleted file mode 100644 index 7ee6bf9..0000000 Binary files a/frontend/build/logo192.png and /dev/null differ diff --git a/frontend/build/logo512.png b/frontend/build/logo512.png deleted file mode 100644 index eba667e..0000000 Binary files a/frontend/build/logo512.png and /dev/null differ diff --git a/frontend/build/manifest.json b/frontend/build/manifest.json deleted file mode 100644 index cbc6859..0000000 --- a/frontend/build/manifest.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "short_name": "TOEIC", - "name": "TOEIC", - "icons": [ - { - "src": "icons/logo16.png", - "type": "image/png", - "sizes": "16x16" - }, - { - "src": "icons/logo24.png", - "type": "image/png", - "sizes": "24x24" - }, - { - "src": "icons/logo32.png", - "type": "image/png", - "sizes": "32x32" - }, - { - "src": "icons/logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "icons/logo512.png", - "type": "image/png", - "sizes": "512x512" - } - ], - "start_url": ".", - "display": "standalone", - "theme_color": "#000000", - "background_color": "#ffffff", - "shortcuts": [ - { - "name": "TOEIC", - "short_name": "TOEIC", - "description": "다양한 토익 기출문제를 제공합니다!", - "url": ".", - "icons": [{ "src": "/img/logo192.png", "sizes": "192x192" }] - } - ], - "description": "TOEIC", - "screenshots": [ - { - "src": "img/snapshot.png", - "sizes": "640x320", - "type": "image/png", - "form_factor": "wide", - "label": "Wonder Widgets" - } - ] -} diff --git a/frontend/build/robots.txt b/frontend/build/robots.txt deleted file mode 100644 index e9e57dc..0000000 --- a/frontend/build/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -# https://www.robotstxt.org/robotstxt.html -User-agent: * -Disallow: diff --git a/frontend/src/apis/BaseUrl.ts b/frontend/src/apis/BaseUrl.ts index b3edd4b..787aee1 100644 --- a/frontend/src/apis/BaseUrl.ts +++ b/frontend/src/apis/BaseUrl.ts @@ -1,3 +1,13 @@ import axios from 'axios'; -export default axios.create({ baseURL: 'https://api.doit-toeic.xyz' }); +export default axios.create({ + baseURL: 'https://api.doit-toeic.xyz', + headers: { + 'Content-Type': 'application/json', + }, +}); + +export const httpClientForCredentials = axios.create({ + baseURL: 'https://api.doit-toeic.xyz', + withCredentials: true, +}); diff --git a/frontend/src/apis/FetchRegister.ts b/frontend/src/apis/FetchRegister.ts deleted file mode 100644 index 977789f..0000000 --- a/frontend/src/apis/FetchRegister.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { RegisterData } from '../types/RegisterData'; -import url from './BaseUrl'; - -export const FetchRegister = async (register: RegisterData) => { - const data = { email: register.email, password: register.password }; - - const headers = { - 'Content-Type': 'application/json', - }; - - try { - const res = await url.post('/auth/register', data, { headers }); - res && alert('회원가입이 완료되었습니다.'); - return res.data; - } catch (error) { - alert('회원가입이 실패하였습니다.'); - throw new Error(); - } -}; diff --git a/frontend/src/apis/auth/FetchLogIn.ts b/frontend/src/apis/auth/FetchLogIn.ts new file mode 100644 index 0000000..1bb7cc3 --- /dev/null +++ b/frontend/src/apis/auth/FetchLogIn.ts @@ -0,0 +1,50 @@ +import { httpClientForCredentials } from '../BaseUrl'; +import { LoginData } from '../../types/LoginData'; +import { AxiosError, AxiosResponse } from 'axios'; + +export const onLogInSuccess = async (response: AxiosResponse) => { + const { accessToken, expiresIn } = await response.data.data; + + httpClientForCredentials.defaults.headers.common['Authorization'] = + `Bearer ${accessToken}`; + + const currentTime = new Date(Date.now()); + const tokenExpirationTime = new Date(Date.now() + expiresIn * 1000); + const refreshTime = tokenExpirationTime.getTime() - currentTime.getTime(); + console.log('accessToken', response.data.message); + + setTimeout(() => { + FetchRefreshToken(); + }, refreshTime); +}; + +export const FetchRefreshToken = async () => { + try { + const res = await httpClientForCredentials.get('/auth/refresh'); + + if (res.status === 200) { + onLogInSuccess(res); + console.log('refresh', res.data.message); + } + } catch (err) { + const axiosError = err as AxiosError; + if (axiosError.response?.status === 401) { + alert('로그인 해주세요'); + } + + throw new Error(); + } +}; + +export const FetchLogIn = async (data: LoginData) => { + try { + const response = await httpClientForCredentials.post('/auth/login', data); + + if (response.status === 200) { + onLogInSuccess(response); + } + } catch (err) { + console.log('로그인 에러 발생', err); + throw new Error(); + } +}; diff --git a/frontend/src/apis/auth/FetchRegister.ts b/frontend/src/apis/auth/FetchRegister.ts new file mode 100644 index 0000000..ce2c1d1 --- /dev/null +++ b/frontend/src/apis/auth/FetchRegister.ts @@ -0,0 +1,16 @@ +import { RegisterData } from '../../types/RegisterData'; +import url from '../BaseUrl'; + +export const FetchRegister = async (register: RegisterData) => { + const data = { email: register.email, password: register.password }; + + try { + const res = await url.post('/auth/register', data); + if (res.status === 201) { + alert('회원가입이 완료되었습니다.이메일을 확인해주세요!!'); + } + } catch (error) { + alert('회원가입이 실패하였습니다.'); + throw new Error(); + } +}; diff --git a/frontend/src/components/common/Button.tsx b/frontend/src/components/common/Button.tsx index d786ca2..ca59850 100644 --- a/frontend/src/components/common/Button.tsx +++ b/frontend/src/components/common/Button.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { ButtonCSS } from '../../style/components/common/ButtonCSS'; import { useNavigate } from 'react-router-dom'; -import { ButtonProps } from '../../types/ButtonPtops'; +import { ButtonProps } from '../../types/ButtonProps'; function Button({ children, diff --git a/frontend/src/components/login/LoginForm.tsx b/frontend/src/components/login/LoginForm.tsx index 51891fd..f54d360 100644 --- a/frontend/src/components/login/LoginForm.tsx +++ b/frontend/src/components/login/LoginForm.tsx @@ -1,37 +1,39 @@ import React from 'react'; import { LoginFormCSS } from '../../style/components/login/LoginFormCSS'; import { SubmitHandler, useForm } from 'react-hook-form'; -import { FormData } from '../../types/LoginData'; +import { LoginData } from '../../types/LoginData'; import SubmitBtn from '../common/SubmitBtn'; +import { FetchLogIn } from '../../apis/auth/FetchLogIn'; function LoginForm() { const { register, handleSubmit, formState: { errors }, - } = useForm(); + } = useForm(); - const onSubmit: SubmitHandler = (data) => { - console.log(data); + const onsubmit: SubmitHandler = (data) => { + FetchLogIn(data); }; return ( <> - +
- {errors.username && 아이디를 작성해주세요!} + {errors.email && 아이디를 작성해주세요!}
diff --git a/frontend/src/components/register/RegisterForm.tsx b/frontend/src/components/register/RegisterForm.tsx index d6b84e7..fffd048 100644 --- a/frontend/src/components/register/RegisterForm.tsx +++ b/frontend/src/components/register/RegisterForm.tsx @@ -3,7 +3,7 @@ import { SubmitHandler, useForm } from 'react-hook-form'; import { RegisterData } from '../../types/RegisterData'; import Agreement from './Agreement'; import SubmitBtn from '../common/SubmitBtn'; -import { FetchRegister } from '../../apis/FetchRegister'; +import { FetchRegister } from '../../apis/auth/FetchRegister'; import { useNavigate } from 'react-router-dom'; function RegisterForm() { diff --git a/frontend/src/style/components/common/ButtonCSS.ts b/frontend/src/style/components/common/ButtonCSS.ts index bcefe62..e10075f 100644 --- a/frontend/src/style/components/common/ButtonCSS.ts +++ b/frontend/src/style/components/common/ButtonCSS.ts @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import { ButtonProps } from '../../../types/ButtonPtops'; +import { ButtonProps } from '../../../types/ButtonProps'; import { media } from '../../mediaQuery'; export const ButtonCSS = styled.button` diff --git a/frontend/src/types/ButtonPtops.ts b/frontend/src/types/ButtonProps.ts similarity index 100% rename from frontend/src/types/ButtonPtops.ts rename to frontend/src/types/ButtonProps.ts diff --git a/frontend/src/types/LoginData.ts b/frontend/src/types/LoginData.ts index e4daeea..a2ed8c0 100644 --- a/frontend/src/types/LoginData.ts +++ b/frontend/src/types/LoginData.ts @@ -1,4 +1,4 @@ -export type FormData = { - username: string; +export type LoginData = { + email: string; password: string; };