Skip to content

Commit

Permalink
#125 feat: 로그인 관련 v2 api 모듈화
Browse files Browse the repository at this point in the history
  • Loading branch information
useonglee committed Jun 13, 2022
1 parent 3eb3ea5 commit e64d172
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const createAxios = (): AxiosInstance => {
return axios.create({ baseURL: `${BASE_URL}/api/v1`, headers: HEADERS });
};

const createAxiosWithToken = (): AxiosInstance => {
const requestHTTP = axios.create({ baseURL: `${BASE_URL}/api/v1`, headers: HEADERS });
const createAxiosWithToken = (version: string): AxiosInstance => {
const requestHTTP = axios.create({ baseURL: `${BASE_URL}/api/${version}`, headers: HEADERS, withCredentials: true });

return interceptors(requestHTTP);
};
Expand All @@ -33,7 +33,25 @@ const createAxiosWithTokenInUpload = (): AxiosInstance => {
export const axiosService = createAxios();

// With token
export const axiosWithToken = createAxiosWithToken();
export const axiosWithToken = createAxiosWithToken('v1');

// With token
export const axiosWithTokenInUpload = createAxiosWithTokenInUpload();

interface ApisType {
url: string;
}

class Apis implements ApisType {
constructor(public url: string) {
this.url = url;
}

async fetchUser<bodyDataType>(bodyData: bodyDataType) {
await createAxiosWithToken('v2').post(`/users/${this.url}`, bodyData);
}
}

const api = (url: string) => new Apis(url);

export default api;

0 comments on commit e64d172

Please sign in to comment.