fix: skicka Authorization-header i klientens direktanrop till /api/recipes
Caddy routar /api/recipes* direkt till NestJS (bypassing Next.js). Klient-komponenter maste lagga till JWT-token sjalva via useSession(). Pavaerkade filer: - RecipeDetailClient.tsx (PATCH, DELETE, POST image) - ImportRecipePage.tsx (POST /api/recipes) - WriteRecipePage.tsx (POST /api/recipes)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { fetchJson } from '../../../lib/api';
|
||||
import { parseErrorResponse } from '../../../lib/error-handler';
|
||||
import type { Product } from '../../../features/inventory/types';
|
||||
@@ -37,6 +38,7 @@ type Step = 'input' | 'review' | 'saving';
|
||||
|
||||
export default function ImportRecipePage() {
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession();
|
||||
const [step, setStep] = useState<Step>('input');
|
||||
const [markdown, setMarkdown] = useState('');
|
||||
const [parsed, setParsed] = useState<ParseResult | null>(null);
|
||||
@@ -136,7 +138,7 @@ export default function ImportRecipePage() {
|
||||
try {
|
||||
const res = await fetch('/api/recipes', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session?.accessToken}` },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user