fix: await params in Next.js 16 dynamic route handlers
This commit is contained in:
@@ -2,10 +2,10 @@ import { NextResponse } from 'next/server';
|
|||||||
import { requireAdminAuth } from '@/lib/adminAuth';
|
import { requireAdminAuth } from '@/lib/adminAuth';
|
||||||
import { engineFetch } from '@/lib/engine';
|
import { engineFetch } from '@/lib/engine';
|
||||||
|
|
||||||
export async function PATCH(req, { params }) {
|
export async function PATCH(req, context) {
|
||||||
await requireAdminAuth();
|
await requireAdminAuth();
|
||||||
try {
|
try {
|
||||||
const data = await engineFetch(`/api/drafts/${params.id}/approve`, { method: 'PATCH' });
|
const data = await engineFetch(`/api/drafts/${(await context.params).id}/approve`, { method: 'PATCH' });
|
||||||
return NextResponse.json(data);
|
return NextResponse.json(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { NextResponse } from 'next/server';
|
|||||||
import { requireAdminAuth } from '@/lib/adminAuth';
|
import { requireAdminAuth } from '@/lib/adminAuth';
|
||||||
import { engineFetch } from '@/lib/engine';
|
import { engineFetch } from '@/lib/engine';
|
||||||
|
|
||||||
export async function POST(req, { params }) {
|
export async function POST(req, context) {
|
||||||
await requireAdminAuth();
|
await requireAdminAuth();
|
||||||
try {
|
try {
|
||||||
const body = await req.json().catch(() => ({}));
|
const body = await req.json().catch(() => ({}));
|
||||||
const data = await engineFetch(`/api/drafts/${params.id}/regenerate-cover`, {
|
const data = await engineFetch(`/api/drafts/${(await context.params).id}/regenerate-cover`, {
|
||||||
method: 'POST', body: JSON.stringify(body),
|
method: 'POST', body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
return NextResponse.json(data);
|
return NextResponse.json(data);
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { NextResponse } from 'next/server';
|
|||||||
import { requireAdminAuth } from '@/lib/adminAuth';
|
import { requireAdminAuth } from '@/lib/adminAuth';
|
||||||
import { engineFetch } from '@/lib/engine';
|
import { engineFetch } from '@/lib/engine';
|
||||||
|
|
||||||
export async function PATCH(req, { params }) {
|
export async function PATCH(req, context) {
|
||||||
await requireAdminAuth();
|
await requireAdminAuth();
|
||||||
try {
|
try {
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const data = await engineFetch(`/api/drafts/${params.id}`, {
|
const data = await engineFetch(`/api/drafts/${(await context.params).id}`, {
|
||||||
method: 'PATCH', body: JSON.stringify(body),
|
method: 'PATCH', body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
return NextResponse.json(data);
|
return NextResponse.json(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user