Files
recipe-app/_archive/frontend/app/api/admin/inventory-item/route.ts
T
Nils-Johan Gynther ffe50e5151
Test Suite / test (24.15.0) (push) Has been cancelled
feat: add TypeScript definitions for next-auth session with accessToken and user details
2026-05-04 20:09:21 +02:00

31 lines
888 B
TypeScript

import { NextResponse } from 'next/server';
import { auth } from '../../../../auth';
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
export async function POST(req: Request) {
const session = await auth();
if (!session?.accessToken) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const body = await req.json();
const res = await fetch(`${API_BASE}/api/inventory`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session.accessToken}`,
},
body: JSON.stringify(body),
cache: 'no-store',
});
if (!res.ok) {
const text = await res.text();
return NextResponse.json({ error: text || 'Kunde inte skapa inventory-rad' }, { status: res.status });
}
return NextResponse.json({ ok: true });
}