Skip to content

Commit

Permalink
refactor: 로그인 상태 여부에 따른 클라이언트 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
im-na0 committed Jun 27, 2024
1 parent 37033c3 commit 98aa3bf
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/apis/fetchRoom.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import axios from "axios";

import { axiosInstance } from "./axiosInstance";

import type { ResponseData } from "@/types/responseType";
import type { RoomData } from "@/types/room";

import { ACCESS_TOKEN, BASE_URL, END_POINTS } from "@/constants/api";
import { BASE_URL, END_POINTS } from "@/constants/api";

export const getRoom = async (
productId: string,
isLoggedIn: boolean,
): Promise<RoomData> => {
const headers: Record<string, string> = {};

if (isLoggedIn) {
const accessToken = localStorage.getItem(ACCESS_TOKEN);
headers["Authorization"] = `${accessToken}`;
}
const client = isLoggedIn ? axiosInstance : axios;
const url = isLoggedIn
? END_POINTS.ROOM(productId)
: `${BASE_URL}${END_POINTS.ROOM(productId)}`;

const { data } = await axios.get<ResponseData<RoomData>>(
`${BASE_URL}${END_POINTS.ROOM(productId)}`,
{ headers },
);
const { data } = await client.get<ResponseData<RoomData>>(url);

return data.data;
};

0 comments on commit 98aa3bf

Please sign in to comment.