-
+
@@ -1742,6 +2243,40 @@ document.addEventListener('alpine:init', () => { const audio = new Audio(); audio.preload = 'auto'; + // ----------------------------------------------------------------------- + // User store + // ----------------------------------------------------------------------- + Alpine.store('user', { + profile: null, + + init() { + this.load(); + }, + + async load() { + try { + const res = await fetch('/api/player/me'); + if (!res.ok) throw new Error('failed'); + this.profile = await res.json(); + } catch { + this.profile = null; + } + }, + + initials() { + const name = this.profile?.name || ''; + return name.trim().charAt(0) || '?'; + }, + + format(value) { + return new Intl.NumberFormat().format(value || 0); + }, + + logout() { + window.location.href = '/logout'; + }, + }); + // ----------------------------------------------------------------------- // Player store // -----------------------------------------------------------------------