feat: added a login page with Authentik authentication
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user