Skip to content

Commit

Permalink
[Fix]: 서버 로그인 로직 변경에 따른 AccessToken, RefeshToken 쿠키 세팅 제거 및 landingSt…
Browse files Browse the repository at this point in the history
…atus 제거 (#87)

* fix: 논리 테스트

* fix: sentry 논리판단 되돌리기

* chore: console 테스트

* fix: cookie base-url 상위 도메인으로 변경

* fix: landingStatus 로직 제거

* fix: 메인화면 지원하기 버튼 dashboard로 라우트

* fix:landingStatus 삭제 및 쿠키로직 수정

* fix: landingStatus 관련된 모든 로직 제거

* fix: 쿠키 판단 로직 재건

* fix: 필요없는 guard 모두 삭제

* fix: 리다이렉트 정리

* fix: 로그인 유지 시간 sessionStorage에서 확인

* fix: 쿠키 관련 도메인 로직 모두 삭제

* fix: Cookie 관련 모든 로직 삭제

* fix: 빌드에러 터지는거 해결

* fix: 서버에서 refresh갱신 실패할때 로그아웃 처리

* fix: 403 에러 왔을때 세션 만료

* fix: 모집 기간 마감 예외처리

* fix: 파일 확장명 변경
  • Loading branch information
eugene028 authored Aug 7, 2024
1 parent 91c5e2b commit ec0f37a
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 519 deletions.
12 changes: 3 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import styled from '@emotion/styled';
import { css } from '@emotion/react';
import GlobalSize from '@/constants/globalSize';
import { useNavigate } from 'react-router-dom';
import { getAuthRedirectPath } from '@/utils/auth';
import 'react-toastify/dist/ReactToastify.css';
import useLandingStatus from '@/hooks/zustand/useLandingStatus';
import RoutePath from './routes/routePath';

const IMG_SRC = [
'/onboarding/1.png',
Expand All @@ -29,7 +28,6 @@ const IMG_SRC = [

function App() {
const navigate = useNavigate();
const { landingStatus } = useLandingStatus();

return (
<Wrapper direction="column">
Expand Down Expand Up @@ -162,12 +160,8 @@ function App() {
<JoinText />
<OnboardingLogo2 />
<Space height={25} />
<ApplyButton
disabled={landingStatus === 'ONBOARDING_CLOSED'}
onClick={() => navigate(getAuthRedirectPath(landingStatus))}>
{landingStatus === 'ONBOARDING_CLOSED'
? '지금은 지원 기간이 아니에요'
: '가입하기'}
<ApplyButton onClick={() => navigate(RoutePath.Dashboard)}>
가입하기
</ApplyButton>
<Space height={40} />
</BlueSection>
Expand Down
11 changes: 7 additions & 4 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BASE_URL, DEV_AUTH_TOKEN } from '@/constants/environment';
import useAuthToken from '@/hooks/auth/useAuthToken';
import axios from 'axios';

const apiClient = axios.create({
Expand All @@ -8,8 +7,12 @@ const apiClient = axios.create({
withCredentials: true
});

apiClient.defaults.headers.common['Authorization'] = DEV_AUTH_TOKEN
? `${DEV_AUTH_TOKEN}`
: `Bearer ${useAuthToken().accessToken}`;
export function setAuthHeader() {
if (DEV_AUTH_TOKEN) {
apiClient.defaults.headers.common['Authorization'] = DEV_AUTH_TOKEN;
}
}

setAuthHeader();

export default apiClient;
3 changes: 2 additions & 1 deletion src/components/ApiErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default function ApiErrorBoundary({ children }: PropsWithChildren) {
case 401:
case 403:
toast.error(message);
redirect(RoutePath.Index);
sessionStorage.setItem('isLogin', 'false');
redirect(RoutePath.Home);
break;
default:
toast.error(message);
Expand Down
24 changes: 18 additions & 6 deletions src/components/auth/guard/AuthAccessGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import useLandingStatus from '@/hooks/zustand/useLandingStatus';
import { useEffect } from 'react';
import { Outlet } from 'react-router-dom';
import RoutePath from '@/routes/routePath';
import { isAuthenticated } from '@/utils/auth';
import { toast } from 'react-toastify';
import { useNavigate, Outlet } from 'react-router-dom';
import { useEffect, useState } from 'react';

export default function AuthAccessGuard() {
const { clearLandingStatus } = useLandingStatus();
const navigate = useNavigate();
const [redirect, setRedirect] = useState(false);

useEffect(() => {
clearLandingStatus();
if (!isAuthenticated()) {
toast.error('로그인이 필요한 서비스예요.');
setRedirect(true);
}
}, []);

return <Outlet />;
useEffect(() => {
if (redirect) {
navigate(RoutePath.Home);
}
}, [redirect, navigate]);

return isAuthenticated() ? <Outlet /> : null;
}
14 changes: 0 additions & 14 deletions src/components/auth/guard/MypageAccessGuard.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/components/auth/guard/OnboardingClosedAccessGuard.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/components/auth/guard/OnboardingNotOpenedAccessGuard.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/auth/guard/SignupAccessGuard.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/auth/guard/StudentVerificationAccessGuard.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/auth/guard/index.ts

This file was deleted.

19 changes: 9 additions & 10 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { Logo } from '@/assets/LogoIcon';
import { Flex } from '@/components/common/Wrapper';
import { JoinButton } from '@/components/layout/JoinButton';
import GlobalSize from '@/constants/globalSize';
import useLandingStatus from '@/hooks/zustand/useLandingStatus';
import RoutePath from '@/routes/routePath';
import { color } from 'wowds-tokens';
import { media } from '@/styles';
import { getAuthRedirectPath } from '@/utils/auth';
import styled from '@emotion/styled';
import { useLocation, useNavigate } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { isAuthenticated } from '@/utils/auth';

//TODO: 백엔드 로그인 로직 수정 이후 반영 필요
export default function Header() {
const navigation = useNavigate();
const { pathname } = useLocation();
const { landingStatus } = useLandingStatus();

const handleClick = () => {
navigation(getAuthRedirectPath(landingStatus));
if (isAuthenticated()) navigation(RoutePath.Dashboard);
else {
navigation(RoutePath.GithubSignin);
}
};

return (
Expand All @@ -29,11 +30,9 @@ export default function Header() {
<HeaderLogo />
</Flex>
</LogoContainer>

{landingStatus === 'TO_DASHBOARD' && (
{isAuthenticated() ? (
<JoinButton onClick={handleClick}>내 정보</JoinButton>
)}
{pathname === '/' && landingStatus !== 'TO_DASHBOARD' && (
) : (
<JoinButton onClick={handleClick}>로그인/가입하기</JoinButton>
)}
</HeaderContainter>
Expand Down
6 changes: 3 additions & 3 deletions src/components/myPage/ApproveBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ApproveBox = ({
};
return (
<>
{currentRecruitment.period.open ? (
{currentRecruitment ? (
<BoxWrapper
onClick={() => {
if (role === 'ASSOCIATE') handleBottomSheet();
Expand All @@ -66,8 +66,8 @@ export const ApproveBox = ({
) : (
<Box
variant="warn"
text="학회원 모집이 마감되었어요"
subText="2학기 모집 소식을 받고 싶으시다면 @gdsc.hongik 을 팔로우 해주세요."
text="지금은 모집 기간이 아니에요."
subText="모집 기간에 다시 확인해주세요!"
status="error"
/>
)}
Expand Down
5 changes: 2 additions & 3 deletions src/components/myPage/AssociateRequirementCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ const AssociateRequirementCheck = ({
: '기본 회원 정보를 모두 입력했어요.'
}
onClick={() => {
if (infoStatus === 'PENDING')
navigate(RoutePath.AuthenticationProcess3_Signup);
if (infoStatus === 'PENDING') navigate(RoutePath.Signup);
}}
status={infoStatus === 'PENDING' ? 'error' : 'success'}
variant={infoStatus === 'PENDING' ? 'arrow' : 'text'}
Expand All @@ -90,7 +89,7 @@ const AssociateRequirementCheck = ({
/>
<Box
onClick={() => {
navigate(RoutePath.AuthenticationProcess2_StudentVerification);
navigate(RoutePath.StudentVerification);
}}
text={univStatusContent(univStatus)}
status={univStatus === 'SATISFIED' ? 'success' : 'error'}
Expand Down
5 changes: 1 addition & 4 deletions src/components/myPage/BasicUserInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Flex, Text } from '@/components/common/Wrapper';
import { User } from '@/types/user';
import useLandingStatus from '@/hooks/zustand/useLandingStatus';
import { logout } from '@/utils/auth';
import { typography, color } from 'wowds-tokens';

import { useNavigate } from 'react-router-dom';

const BasicUserInfo = ({ member }: { member: User }) => {
const navigate = useNavigate();
const { clearLandingStatus } = useLandingStatus();

const handleLogoutClick = () => {
clearLandingStatus();
logout();

navigate('/');
location.reload();
};

return (
Expand Down
11 changes: 0 additions & 11 deletions src/constants/landingStatus.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/hooks/auth/useAuthToken.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/hooks/mutation/useCreateUserBasicInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { useNavigate } from 'react-router-dom';

export default function useCreateUserBasicInfo() {
const navigation = useNavigate();
// const { updateLandingStatue } = useLandingStatus();

const { mutate: createBasicInfo, ...rest } = useMutation({
mutationFn: createBasicInfoApi.BASIC_INFO,
onSuccess: () => {
// updateLandingStatue(LandingStatus.Dashboard);
navigation(RoutePath.Dashboard, { replace: true });
}
});
Expand Down
31 changes: 0 additions & 31 deletions src/hooks/zustand/useLandingStatus.ts

This file was deleted.

19 changes: 3 additions & 16 deletions src/pages/Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
import { GitHubButton } from '@/components/auth/GitHubButton';
import { Text } from '@/components/common/Wrapper';
import useLandingStatus from '@/hooks/zustand/useLandingStatus';
import RoutePath from '@/routes/routePath';
import { color, space } from 'wowds-tokens';
import { media } from '@/styles';
import { setCookie } from '@/utils/auth';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import GlobalSize from '@/constants/globalSize';
import { useEffect } from 'react';
import { Link } from 'react-router-dom';

/** 깃허브 로그인 및 가입하기 */
export const Auth = () => {
const { clearLandingStatus } = useLandingStatus();

useEffect(() => {
clearLandingStatus();
// 로그인을 위한 oauth-base-uri 쿠키 값 세팅

setCookie({
key: 'oauth-base-uri',
value: window.location.origin,
encoding: false
});
}, []);

const handleClick = () => {
//TODO: QA용으로 임시로 설정
sessionStorage.setItem('isLogin', 'true');

// GitHub 로그인 페이지로 직접 리다이렉트
setTimeout(function () {
document.location.href = RoutePath.AuthGithubLoginRedirect;
Expand Down
Loading

0 comments on commit ec0f37a

Please sign in to comment.