mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
디렉터리 탐색 중 액세스 토큰이 만료됐을 때 로그인 페이지로 리다이렉션되던 문제 수정
This commit is contained in:
@@ -1,41 +1,54 @@
|
||||
import { signRequestBody } from "$lib/modules/crypto";
|
||||
|
||||
export const refreshToken = async () => {
|
||||
return await fetch("/api/auth/refreshToken", { method: "POST" });
|
||||
export const refreshToken = async (fetchInternal = fetch) => {
|
||||
return await fetchInternal("/api/auth/refreshToken", { method: "POST" });
|
||||
};
|
||||
|
||||
const callApi = async (input: RequestInfo, init?: RequestInit) => {
|
||||
let res = await fetch(input, init);
|
||||
const callApi = async (input: RequestInfo, init?: RequestInit, fetchInternal = fetch) => {
|
||||
let res = await fetchInternal(input, init);
|
||||
if (res.status === 401) {
|
||||
res = await refreshToken();
|
||||
if (!res.ok) {
|
||||
return res;
|
||||
}
|
||||
res = await fetch(input, init);
|
||||
res = await fetchInternal(input, init);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
export const callGetApi = async (input: RequestInfo) => {
|
||||
return await callApi(input);
|
||||
export const callGetApi = async (input: RequestInfo, fetchInternal?: typeof fetch) => {
|
||||
return await callApi(input, undefined, fetchInternal);
|
||||
};
|
||||
|
||||
export const callPostApi = async <T>(input: RequestInfo, payload: T) => {
|
||||
return await callApi(input, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
export const callPostApi = async <T>(
|
||||
input: RequestInfo,
|
||||
payload: T,
|
||||
fetchInternal?: typeof fetch,
|
||||
) => {
|
||||
return await callApi(
|
||||
input,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
fetchInternal,
|
||||
);
|
||||
};
|
||||
|
||||
export const callSignedPostApi = async <T>(input: RequestInfo, payload: T, signKey: CryptoKey) => {
|
||||
return await callApi(input, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
export const callSignedPostApi = async <T>(
|
||||
input: RequestInfo,
|
||||
payload: T,
|
||||
signKey: CryptoKey,
|
||||
fetchInternal?: typeof fetch,
|
||||
) => {
|
||||
return await callApi(
|
||||
input,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: await signRequestBody(payload, signKey),
|
||||
},
|
||||
body: await signRequestBody(payload, signKey),
|
||||
});
|
||||
fetchInternal,
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user