refactor: useAuthFetch-hook för automatisk JWT-header i klientanrop
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useAuthFetch } from '../../../lib/use-auth-fetch';
|
||||
import { fetchJson } from '../../../lib/api';
|
||||
import { parseErrorResponse } from '../../../lib/error-handler';
|
||||
import type { Product } from '../../../features/inventory/types';
|
||||
@@ -37,7 +37,7 @@ type Step = 'input' | 'review' | 'saving' | 'saved';
|
||||
|
||||
export default function WriteRecipePage() {
|
||||
const router = useRouter();
|
||||
const { data: session } = useSession();
|
||||
const authFetch = useAuthFetch();
|
||||
const [step, setStep] = useState<Step>('input');
|
||||
const [markdown, setMarkdown] = useState('');
|
||||
const [parsed, setParsed] = useState<ParseResult | null>(null);
|
||||
@@ -193,9 +193,8 @@ export default function WriteRecipePage() {
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/recipes', {
|
||||
const res = await authFetch('/api/recipes', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session?.accessToken}` },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user