|
- "use client";
-
- import { NEXT_PUBLIC_API_URL } from "@/config/api";
- import { WarehouseResult } from "./index";
-
- export const fetchWarehouseListClient = async (): Promise<WarehouseResult[]> => {
- const token = localStorage.getItem("accessToken");
-
- const response = await fetch(`${NEXT_PUBLIC_API_URL}/warehouse`, {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- ...(token && { Authorization: `Bearer ${token}` }),
- },
- });
-
- if (!response.ok) {
- if (response.status === 401) {
- throw new Error("Unauthorized: Please log in again");
- }
- throw new Error(`Failed to fetch warehouses: ${response.status} ${response.statusText}`);
- }
-
- return response.json();
- };
|