Rework to use marbas and authentik instead of poketbase (#1)

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2024-05-17 23:00:52 +02:00
parent 9fb78329cc
commit 717eaa6ed8
47 changed files with 2306 additions and 1049 deletions

View File

@@ -1,25 +1,39 @@
import { useAuthStore } from '@/auth';
import axios, { AxiosInstance } from 'axios';
import log from 'loglevel';
export const logResource = (a: AxiosInstance) => {
a.interceptors.response.use(r => {
log.debug(`[${r.config.method?.toUpperCase()}] ${r.config.url}`);
return r;
}, e => {
log.error(`[${e.config.method?.toUpperCase()}] ${e.config.url} failed with ${e.response?.status} ${e.response?.statusText}`);
if (!e?.config) {
log.error(e.message, e);
}
log.error(`[${e.config?.method?.toUpperCase()}] ${e.config?.url} failed with ${e.response?.status} ${e.response?.statusText}`, e);
return Promise.reject(e);
});
}
export const marbasAxiosInstance = axios.create({
baseURL: '/marbas/',
baseURL: import.meta.env.VITE_MARBAS_URL,
headers: {
'accept': 'application/json',
"Content-Type": "application/json"
'Accept': 'application/json',
"Content-Type": "application/json",
},
})
marbasAxiosInstance.interceptors.request.use(r => {
const authStore = useAuthStore();
if (!authStore.isLoggedIn) {
throw new Error("Not logged in");
}
const accessToken = authStore.accessToken;
if (accessToken) {
r.headers.Authorization = `Bearer ${accessToken}`;
}
if (!r.params?.page_size) {
r.params = { ...r.params, page_size: 250 };
}
@@ -44,9 +58,9 @@ marbasAxiosInstance.interceptors.response.use(async r => {
})
export const esiAxiosInstance = axios.create({
baseURL: '/esi/',
baseURL: import.meta.env.VITE_ESI_URL,
headers: {
'accept': 'application/json',
'Accept': 'application/json',
"Content-Type": "application/json"
},
})