26 lines
842 B
TypeScript
26 lines
842 B
TypeScript
import { UpEndApi } from '@upnd/upend';
|
|
import { UpEndWasmExtensionsWeb } from '@upnd/upend/wasm/web';
|
|
import wasmURL from '@upnd/wasm-web/upend_wasm_bg.wasm?url';
|
|
import { type StartStopNotifier, writable, type Writable } from 'svelte/store';
|
|
|
|
const wasm = new UpEndWasmExtensionsWeb(wasmURL);
|
|
const api = new UpEndApi({ instanceUrl: '/', wasmExtensions: wasm });
|
|
export default api;
|
|
|
|
export const currentUser: Writable<string | undefined> = writable(
|
|
undefined as string | undefined,
|
|
((set) => {
|
|
api.authStatus().then((result) => set(result?.user));
|
|
}) 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();
|
|
}
|