feat(frontend): added frontend

- Router: client side route handling with client side rendering
- Toast: rought Toast handling for better UX and messaging
- Auth: single point of truth for the Logged in user

This commit doesnt not include the openapi generated code
This commit is contained in:
Maieul BOYER 2025-11-10 17:00:21 +01:00 committed by Maix0
parent 0db41a440d
commit 08c910c193
28 changed files with 1994 additions and 0 deletions

View file

@ -0,0 +1,51 @@
import { showError } from "@app/toast";
import client from '@app/api';
export type User = {
id: string;
guest: boolean;
name: string;
};
let currentUser: User | null = null;
export function getUser(): Readonly<User> | null {
return currentUser;
}
export function isLogged(): boolean {
return currentUser === null;
}
export function setUser(newUser: User | null) {
currentUser = newUser;
}
export async function updateUser(): Promise<Readonly<User> | null> {
try {
let res = await client.getUser({ user: 'me' });
if (res.kind === "success") {
setUser(res.payload);
return res.payload;
} else if (res.kind === "failure") {
// well no user :D
setUser(null);
return null;
} else if (res.kind === "notLoggedIn") {
setUser(null);
return null;
} else {
setUser(null);
showError(`unknown response: ${JSON.stringify(res)}`);
return null;
}
} catch (e) {
setUser(null);
showError(`failed to get user: ${e}`);
return null;
}
}
Object.assign(window as any, { getUser, setUser, updateUser, isLogged });