Skip to content

Commit

Permalink
Typo(mogua-station#123): fetch 모듈 함수 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Stilllee committed Jan 22, 2025
1 parent c78fc4f commit c19da65
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 55 deletions.
55 changes: 0 additions & 55 deletions src/lib/user/clientFetch.ts

This file was deleted.

29 changes: 29 additions & 0 deletions src/lib/user/fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interface FetchOptions extends RequestInit {
auth?: boolean;
}

/**
* 토큰 주입 방식
* 1. 유저가 필요한 요청:
* await fetcher('/user/profile/me', token, {auth: true});
* 2. 유저가 필요 없는 요청:
* await fetcher('/user/userId, token);
*/
export async function fetcher(
url: string,
token: string,
{ auth, headers, ...options }: FetchOptions = {},
) {
const config = {
...options,
headers: {
...(!(options.body instanceof FormData) && {
"Content-Type": "application/json",
}),
...(auth && token && { Authorization: `Bearer ${token}` }),
...headers,
},
};

return fetch(`${process.env.NEXT_PUBLIC_BASE_URL}${url}`, config);
}

0 comments on commit c19da65

Please sign in to comment.