Skip to content

Commit

Permalink
Merge pull request #1530 from 42organization/fix/#1514-login-page-error
Browse files Browse the repository at this point in the history
[test-deploy] 401 에러처리
  • Loading branch information
cweedlee authored Sep 2, 2024
2 parents 920b948 + ca333ba commit 3429429
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Layout/LayoutProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AdminAppLayout from 'Layout/AdminLayout';
import AgendaAppLayout from 'Layout/AgendaLayout';
import TakguAppLayout from 'Layout/TakguLayout';
import { usePathname } from 'hooks/agenda/Layout/usePathname';
import useAxiosResponse from 'hooks/useAxiosResponse';

type LayoutProviderProps = {
children: React.ReactNode;
Expand All @@ -13,6 +14,7 @@ type LayoutProviderProps = {
// 로그인 스테이트 등은 각 레이아웃에서 확인
const LayoutProvider = ({ children }: LayoutProviderProps) => {
const isLogin = useRecoilValue(loginState);
useAxiosResponse();
console.log(isLogin);
const app = usePathname();
switch (app) {
Expand Down
2 changes: 1 addition & 1 deletion Layout/TakguLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function TakguLayout({ children }: TakguLayoutProps) {
const presentPath = usePathname();
const openCurrentMatch = useRecoilValue(openCurrentMatchState);

useAxiosResponse();
// useAxiosResponse();
useGetUserSeason(presentPath);
useSetAfterGameModal();
useLiveCheck(presentPath);
Expand Down
10 changes: 8 additions & 2 deletions hooks/useAxiosResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosError, AxiosResponse } from 'axios';
import Cookies from 'js-cookie';
import { useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { instance } from 'utils/axios';
import { instance, instanceInAgenda } from 'utils/axios';
import { errorState } from 'utils/recoil/error';
import { loginState } from 'utils/recoil/login';

Expand Down Expand Up @@ -50,6 +50,11 @@ export default function useAxiosResponse() {
(response: AxiosResponse) => response,
errorResponseHandler
);
const responseInAgendaInterceptor =
instanceInAgenda.interceptors.response.use(
(response: AxiosResponse) => response,
errorResponseHandler
);

useEffect(() => {
if (localStorage.getItem('42gg-token')) {
Expand All @@ -63,6 +68,7 @@ export default function useAxiosResponse() {
useEffect(() => {
return () => {
instance.interceptors.response.eject(responseInterceptor);
instance.interceptors.response.eject(responseInAgendaInterceptor);
};
}, [responseInterceptor]);
}, [responseInterceptor, responseInAgendaInterceptor]);
}

0 comments on commit 3429429

Please sign in to comment.