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

@ -1,53 +1,10 @@
import { NextRequest } from "next/server";
import {
clearAuthCookie,
getAccessToken,
getHermesUrl,
hermesJsonResponse,
unauthorizedResponse,
upstreamConfigurationErrorResponse,
upstreamUnavailableResponse,
} from "@/lib/server/hermes";
import { proxyHermesRequest } from "@/lib/server/hermes-proxy";
import { assertSameOrigin } from "@/lib/server/request-guards";
async function proxyUsersRequest(request: NextRequest) {
const token = await getAccessToken();
if (!token) {
return unauthorizedResponse();
}
const hermesUrl = getHermesUrl();
if (!hermesUrl) {
return upstreamConfigurationErrorResponse();
}
let hermesResponse: Response;
try {
hermesResponse = await fetch(`${hermesUrl}/users${request.nextUrl.search}`, {
method: request.method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "application/json",
},
body: request.method === "GET" ? 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);
return proxyHermesRequest(request, `/users${request.nextUrl.search}`);
}
export async function GET(request: NextRequest) {