Skip to content

Commit

Permalink
Merge pull request #72 from Gosrock/dev
Browse files Browse the repository at this point in the history
배포 준비
  • Loading branch information
9yujin authored Aug 16, 2022
2 parents 858bc2d + 1ac6928 commit 3b39ee4
Show file tree
Hide file tree
Showing 15 changed files with 12,689 additions and 14,448 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# 고스락 티켓 예매 프로젝트 2.0
![Frame 34257](https://user-images.githubusercontent.com/55226431/184820864-e8573a2b-b48d-4eb9-a5f7-25ecf7192ec6.png)


# 고스락 티켓 2.0<img src="https://user-images.githubusercontent.com/55226431/184821608-3b631082-fefa-48cf-b9d3-bf4902ddcbff.png" align=left width=100>

> We are GOSROCK, Invites you - 프론트엔드 레포지토리
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@types/node": "^16.11.43",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/react-router-dom": "^5.3.3",
"axios": "^0.27.2",
"lodash": "^4.17.21",
"polished": "^4.2.2",
Expand Down
6 changes: 3 additions & 3 deletions src/apis/error/code401Handler.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useCookies } from 'react-cookie';
import useModal from '../../hooks/useModal';
import { axiosPrivate } from '../axios';
import { ICustomError } from './useApiError';
import { useNavigate } from 'react-router-dom';
const useHandle401 = () => {
const navigate = useNavigate();
const removeCookie = useCookies(['accessToken'])[2];

// 401로 요청 실패했던 요청 새로운 accessToken으로 재요청

const handle401 = (error: ICustomError) => {
removeCookie('accessToken');
localStorage.removeItem('accessToken');
localStorage.removeItem('registerToken');
// 새로운 토큰 저장
axiosPrivate.defaults.headers.common.Authorization = '';
navigate('/');
};

return { handle401 };
Expand Down
15 changes: 8 additions & 7 deletions src/apis/error/useErrorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ICustomError } from './useApiError';
import useModal from '../../hooks/useModal';
import { useNavigate } from 'react-router-dom';
import { useCookies } from 'react-cookie';

export type TErrorCode =
| 'ValidationError'
| 'Auth-0000'
| 'Auth-0001'
| 'Auth-0002'
| 'Auth-9000'
| 'Auth-5000'
| 'Auth-1000'
Expand All @@ -18,6 +18,7 @@ const errorMessage = {
ValidationError: '잘못된 값이 입력되었어요',
'Auth-0000': '인증번호의 기한이 만료되었어요',
'Auth-0001': '인증번호가 일치하지 않습니다',
'Auth-0002': '이미 가입된 번호입니다',
'Auth-9000': (
<span>
과도한 요청이에요
Expand All @@ -33,25 +34,25 @@ const errorMessage = {
</div>
),
'Auth-1000': '로그인이 만료되었어요',
'Auth-1001': '이미 가입된 번호입니다',
'Auth-1002': '이미 가입된 번호입니다',
'Auth-1003': '이미 가입된 번호입니다',
'Auth-1001': '로그인이 만료되었어요',
'Auth-1002': '로그인이 만료되었어요',
'Auth-1003': '로그인이 만료되었어요',
};

const useErrorModal = () => {
const { openModal, closeModal } = useModal();
const [, , removeCookie] = useCookies(['registerToken']);
const navigate = useNavigate();
const openErrorModal = (error: ICustomError) => {
const code = error.code as TErrorCode;
console.log(error);
openModal({
modalType: 'Notice',
modalProps: {
onClick: () => {
closeModal();
if (code === 'Auth-1002') {
if (code === 'Auth-0002') {
navigate('/');
removeCookie('registerToken');
localStorage.removeItem('registerToken');
}
},
type: '에러처리',
Expand Down
2 changes: 1 addition & 1 deletion src/components/auth/AuthTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const AuthTemplate = ({
{page === 'send' ? (
<AppBar label={'홈으로'} target="/" />
) : (
<AppBar label={'뒤로 가기'} />
<AppBar label={'뒤로가기'} />
)}
<SetMargin>
<Title>
Expand Down
10 changes: 3 additions & 7 deletions src/components/auth/RefuseAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { authState } from '../../stores/auth';
import { redirectState } from '../../stores/redirect';
import { useCookies } from 'react-cookie';
import useModal from '../../hooks/useModal';

const RefuseAuth = () => {
const { openModal, closeModal } = useModal();
const accessCookie = useCookies(['accessToken'])[0];
const registerCookie = useCookies(['registerToken'])[0];
const accessToken = localStorage.getItem('accessToken');
const registerToken = localStorage.getItem('registerToken');
// undefined or token
const location = useLocation();
console.log(location);
if (accessCookie.accessToken) {
if (accessToken) {
// 어세스 토큰 있으면 마이페이지로 되돌려버림
openModal({
modalType: 'Notice',
Expand All @@ -26,9 +25,6 @@ const RefuseAuth = () => {
},
});
return <Navigate replace to="/mypage" />;
} else if (registerCookie.registerToken) {
// 어세스 토큰 없이 레지스터 토큰만 있으면 회원가입
return <Navigate replace to="/auth/init" />;
} else {
// 둘 다 없으면 로그인 페이지로
return <Outlet />;
Expand Down
10 changes: 4 additions & 6 deletions src/components/auth/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { authState } from '../../stores/auth';
import { redirectState } from '../../stores/redirect';
import { useCookies } from 'react-cookie';

const RequireAuth = () => {
const { pathname } = useLocation();
const setRedirectUri = useSetRecoilState(redirectState);

const accessCookie = useCookies(['accessToken'])[0];
const registerCookie = useCookies(['registerToken'])[0];
const accessToken = localStorage.getItem('accessToken');
const registerToken = localStorage.getItem('registerToken');
// undefined or token
console.log(accessCookie);
useEffect(() => {
setRedirectUri(pathname);
}, []);

if (accessCookie.accessToken) {
if (accessToken) {
// 어세스 토큰 있으면 패스
return <Outlet />;
} else if (registerCookie.registerToken) {
} else if (registerToken) {
// 어세스 토큰 없이 레지스터 토큰만 있으면 회원가입
return <Navigate replace to="/auth/init" />;
} else {
Expand Down
Loading

0 comments on commit 3b39ee4

Please sign in to comment.