30 lines
906 B
TypeScript
30 lines
906 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { cookies } from 'next/headers';
|
|
import { authCookieName } from '../../../../lib/auth';
|
|
|
|
const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api';
|
|
|
|
export async function PATCH(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
) {
|
|
const token = (await cookies()).get(authCookieName)?.value;
|
|
if (!token) {
|
|
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const { id } = await params;
|
|
const body = await request.json();
|
|
const response = await fetch(`${API_URL}/roles/${id}`, {
|
|
method: 'PATCH',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
body: JSON.stringify(body),
|
|
cache: 'no-store',
|
|
});
|
|
const payload = await response.json();
|
|
return NextResponse.json(payload, { status: response.status });
|
|
}
|