This commit is contained in:
2026-06-17 00:21:00 +02:00
commit 408e48c568
41 changed files with 6617 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import { api } from './api';
export type User = {
id: string;
email: string;
display_name: string | null;
email_verified: boolean;
};
export type Settings = {
locale: string;
currency: string;
theme: string;
notify_email: boolean;
};
type Me = { user: User; settings: Settings };
class AuthStore {
user = $state<User | null>(null);
settings = $state<Settings | null>(null);
loaded = $state(false);
async refresh() {
try {
const me = await api.get<Me>('/auth/me');
this.user = me.user;
this.settings = me.settings;
} catch {
this.user = null;
this.settings = null;
} finally {
this.loaded = true;
}
}
set(me: Me) {
this.user = me.user;
this.settings = me.settings;
this.loaded = true;
}
async logout() {
try {
await api.post('/auth/logout');
} finally {
this.user = null;
this.settings = null;
}
}
}
export const auth = new AuthStore();