Refactor BFF Package Structure #64

Merged
stne3960 merged 12 commits from refactor/bff-structure into main 2026-01-12 17:38:55 +01:00
Showing only changes of commit a6b675d9a5 - Show all commits

View File

@ -11,6 +11,32 @@ const includeCredentials: Middleware = {
},
};
function getCookie(name: string): string | undefined {
const match = document.cookie.match(new RegExp(`(^| )${name}=([^;]+)`));
return match ? match[2] : undefined;
}
const includeCsrfToken: Middleware = {
onRequest({ request }) {
const method = request.method.toUpperCase();
if (method === "POST" || method === "PUT" || method === "DELETE") {
const csrfToken = getCookie("XSRF-TOKEN");
if (csrfToken) {
request.headers.set("X-XSRF-TOKEN", csrfToken);
}
}
return request;
},
};
const includeAcceptLanguage: Middleware = {
onRequest({ request }) {
const language = navigator.language.split("-")[0] || "en";
request.headers.set("Accept-Language", language);
return request;
},
};
const initiateAuthorizationOnUnauthorized: Middleware = {
onResponse({ response }) {
if (response.status === 401) {
@ -24,6 +50,8 @@ const initiateAuthorizationOnUnauthorized: Middleware = {
};
client.use(includeCredentials);
client.use(includeCsrfToken);
client.use(includeAcceptLanguage);
client.use(initiateAuthorizationOnUnauthorized);
export function useBackend() {