diff --git a/frontend/app/recipes/write/page.tsx b/frontend/app/recipes/write/page.tsx index 772c7c1f..f8c8575a 100644 --- a/frontend/app/recipes/write/page.tsx +++ b/frontend/app/recipes/write/page.tsx @@ -1,6 +1,8 @@ import Navigation from '../../Navigation'; import WriteRecipePage from './WriteRecipePage'; +export const dynamic = 'force-dynamic'; + export default function Page() { return ( <> diff --git a/frontend/lib/use-auth-fetch.ts b/frontend/lib/use-auth-fetch.ts index ee48b8a1..3d54e1ba 100644 --- a/frontend/lib/use-auth-fetch.ts +++ b/frontend/lib/use-auth-fetch.ts @@ -13,17 +13,20 @@ import { useCallback } from 'react'; * const res = await authFetch('/api/recipes/1', { method: 'PATCH', body: JSON.stringify(data) }); */ export function useAuthFetch() { - const { data: session } = useSession(); + const sessionResult = useSession(); + const accessToken = sessionResult?.data?.accessToken ?? ''; return useCallback( (url: string, init: RequestInit = {}): Promise => { const headers = new Headers(init.headers); - headers.set('Authorization', `Bearer ${session?.accessToken ?? ''}`); + if (accessToken) { + headers.set('Authorization', `Bearer ${accessToken}`); + } if (!headers.has('Content-Type') && init.body && typeof init.body === 'string') { headers.set('Content-Type', 'application/json'); } return fetch(url, { ...init, headers }); }, - [session?.accessToken], + [accessToken], ); }