feat(rbac): add roles and permissions

This commit is contained in:
Schubert Ferenc 2026-07-02 23:05:59 +02:00
parent 86a32a942c
commit 694b7bd09a
37 changed files with 2682 additions and 218 deletions

View file

@ -0,0 +1,55 @@
import { NextRequest } from "next/server";
import {
clearAuthCookie,
getAccessToken,
getHermesUrl,
hermesJsonResponse,
unauthorizedResponse,
upstreamConfigurationErrorResponse,
upstreamUnavailableResponse,
} from "@/lib/server/hermes";
export async function proxyHermesRequest(
request: NextRequest,
path: string,
) {
const token = await getAccessToken();
if (!token) {
return unauthorizedResponse();
}
const hermesUrl = getHermesUrl();
if (!hermesUrl) {
return upstreamConfigurationErrorResponse();
}
let hermesResponse: Response;
try {
hermesResponse = await fetch(`${hermesUrl}${path}`, {
method: request.method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "application/json",
},
body: request.method === "GET" || request.method === "DELETE"
? undefined
: await request.text(),
cache: "no-store",
});
} catch {
return upstreamUnavailableResponse();
}
if (hermesResponse.status === 401) {
const response = await hermesJsonResponse(hermesResponse);
clearAuthCookie(response);
return response;
}
return hermesJsonResponse(hermesResponse);
}