2024-01-22 22:58:55 +01:00
|
|
|
import { UpEndApi } from '@upnd/upend';
|
|
|
|
import { UpEndWasmExtensionsWeb } from '@upnd/upend/wasm/web';
|
|
|
|
import wasmURL from '@upnd/wasm-web/upend_wasm_bg.wasm?url';
|
2024-03-30 16:35:21 +01:00
|
|
|
import { type StartStopNotifier, writable, type Writable } from 'svelte/store';
|
2024-04-04 20:25:04 +02:00
|
|
|
import * as Sentry from '@sentry/sveltekit';
|
2022-02-20 13:06:01 +01:00
|
|
|
|
2023-10-07 13:00:34 +02:00
|
|
|
const wasm = new UpEndWasmExtensionsWeb(wasmURL);
|
2024-03-30 16:35:21 +01:00
|
|
|
const api = new UpEndApi({ instanceUrl: '/', wasmExtensions: wasm });
|
|
|
|
export default api;
|
|
|
|
|
|
|
|
export const currentUser: Writable<string | undefined> = writable(
|
|
|
|
undefined as string | undefined,
|
|
|
|
((set) => {
|
2024-04-04 20:25:04 +02:00
|
|
|
api.authStatus().then((result) => {
|
|
|
|
set(result?.user);
|
|
|
|
Sentry.setUser({ id: result?.user });
|
|
|
|
});
|
2024-03-30 16:35:21 +01:00
|
|
|
}) as StartStopNotifier<string | undefined>
|
|
|
|
);
|
|
|
|
|
|
|
|
export async function login(credentials: { username: string; password: string }) {
|
|
|
|
await api.authenticate(credentials);
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function logout() {
|
|
|
|
await api.resetAuth();
|
|
|
|
window.location.reload();
|
|
|
|
}
|