Skip to content

Commit

Permalink
fix: fetcher 함수에 router dom 상태 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
ukkodeveloper committed Sep 11, 2023
1 parent 406f15d commit e0eeabd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions frontend/src/shared/remotes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useNavigate } from 'react-router-dom';
import ROUTE_PATH from '@/shared/constants/path';

export interface ErrorResponse {
Expand All @@ -9,8 +8,8 @@ export interface ErrorResponse {
const { BASE_URL } = process.env;

const fetcher = async (url: string, method: string, body?: unknown) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const navigate = useNavigate();
const loginRedirectUrl = `${process.env.BASE_URL}${ROUTE_PATH.LOGIN}`?.replace(/api\/?/, '');

const accessToken = localStorage.getItem('userToken');

const headers: Record<string, string> = {
Expand Down Expand Up @@ -38,7 +37,8 @@ const fetcher = async (url: string, method: string, body?: unknown) => {

if (response.status === 401) {
localStorage.removeItem('userToken');
navigate(ROUTE_PATH.LOGIN);
//TODO: 해당 부분 router-dom으로 해결 가능한지 확인해야함.
window.location.href = loginRedirectUrl;
}

if (!response.ok) {
Expand Down

0 comments on commit e0eeabd

Please sign in to comment.