Some tweaks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { API_URL } from "@/lib/constants";
|
||||
import { ApiResponse } from "@/types/types";
|
||||
import { getApiUrl } from "@/utils/api";
|
||||
import { getCookie } from "cookies-next";
|
||||
import { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
|
||||
export default async function request<T>(
|
||||
@@ -20,7 +21,7 @@ export default async function request<T>(
|
||||
|
||||
if (options.csrfToken) {
|
||||
const res: ApiResponse<{ csrf: string }> = await (
|
||||
await fetch(`${API_URL}/csrf-token`, { credentials: "include" })
|
||||
await fetch(`${getApiUrl()}/csrf-token`, { credentials: "include" })
|
||||
).json();
|
||||
if (res.data) headers["X-CSRF-Token"] = res.data.csrf;
|
||||
}
|
||||
@@ -39,7 +40,7 @@ export default async function request<T>(
|
||||
headers.Authorization = `Bearer ${authToken}`;
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}${endpoint}`, {
|
||||
const response = await fetch(`${getApiUrl()}${endpoint}`, {
|
||||
method,
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
|
||||
Reference in New Issue
Block a user