Skip to content

Commit

Permalink
Merge pull request #285 from TripInfoWeb/dev_auth
Browse files Browse the repository at this point in the history
fix: next 속성도 사용할 수 있게 추가
  • Loading branch information
ssssksss authored Sep 10, 2024
2 parents 8e4575d + 5c0bd5b commit f64263d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/getNewAccessTokenAndRerequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IFetchWithTokenRefreshSSR {
method?: string;
cache?: RequestCache;
contentType?: string;
next?: NextFetchRequestConfig | undefined;
}

export async function fetchWithTokenRefreshSSR({
Expand All @@ -40,8 +41,8 @@ export async function fetchWithTokenRefreshSSR({
method,
cache,
contentType,
next,
}: IFetchWithTokenRefreshSSR) {

let response = await fetch(url, {
method: method || "GET",
headers: {
Expand All @@ -63,28 +64,28 @@ export async function fetchWithTokenRefreshSSR({
Cookie: `access_token=${newAccessToken}`,
},
cache: cache || "no-store",
next: next,
});
} else {
throw new Error("새로운 액세스 토큰 발급 실패");
}
}

if (response.status == 403) {
alert("접근 권한이 없음");
throw new Error("접근 권한이 없음");
}

if (response.status == 404) {
alert("잘못된 경로 요청");
throw new Error("잘못된 경로 요청");
}

if (response.status == 405) {
alert("잘못된 메소드 타입");
throw new Error("잘못된 메소드 타입");
}

if (response.status == 409) {
throw new Error("중복된 데이터로 요청에 실패");
}

if (!response.ok) {
throw new Error("API 요청에 실패했습니다.");
}
Expand Down

0 comments on commit f64263d

Please sign in to comment.