feat(api): use dynamic import for auth headers in fetchJson function

This commit is contained in:
Nils-Johan Gynther
2026-04-17 20:29:52 +02:00
parent 8b9ec31dee
commit 28e938e66e
+4 -2
View File
@@ -1,5 +1,4 @@
import { redirect } from 'next/navigation'; import { redirect } from 'next/navigation';
import { getAuthHeaders } from './auth-headers';
const API_BASE = const API_BASE =
process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080'; process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
@@ -11,7 +10,10 @@ export async function fetchJson<T>(path: string, init?: RequestInit): Promise<T>
? (path.startsWith('http') ? path : `${API_BASE}${path}`) ? (path.startsWith('http') ? path : `${API_BASE}${path}`)
: path; : path;
const authHeaders = isServer ? await getAuthHeaders() : {}; // Dynamisk import så att auth-headers inte bundlas till klienten
const authHeaders = isServer
? await (await import('./auth-headers')).getAuthHeaders()
: {};
const res = await fetch(url, { const res = await fetch(url, {
...init, ...init,