feat: added a login page with Authentik authentication

This commit is contained in:
Zakaria
2026-10-16 19:35:27 -04:00
parent 668911ed6e
commit 924e354788
18 changed files with 441 additions and 54 deletions
+14 -6
View File
@@ -1217,6 +1217,13 @@ export function createApiClient(
return { url, init };
});
client.addRequestInterceptor((url, init) => {
if (!['POST', 'PUT', 'PATCH', 'DELETE'].includes(init.method ?? 'GET')) return {url, init};
const csrf = document.cookie.split('; ').find((item) => item.startsWith('floci_ui_csrf='))?.split('=')[1];
if (csrf) (init.headers as Record<string, string>)['X-Floci-CSRF'] = decodeURIComponent(csrf);
return {url, init};
});
// Auth interceptor — attaches Bearer token if available
if (getToken) {
client.addRequestInterceptor(async (url, init) => {
@@ -1237,12 +1244,13 @@ export function createApiClient(
});
}
// client.addResponseInterceptor((res) => {
// if (res.status === 401) {
// handleUnauthorizedApiResponse();
// }
// return res;
// });
client.addResponseInterceptor((res) => {
if (res.status === 401 && !res.url.includes('/api/auth/')) {
const returnTo = `${window.location.pathname}${window.location.search}`;
window.location.assign(`/login?returnTo=${encodeURIComponent(returnTo)}`);
}
return res;
});
return client;
}