05f8e2e3b6
- Create reusable components: auth, api-client, shared-types - ModeTemplate with Hono backend and SvelteKit frontend - Auth store refactored to class-based Svelte 5 pattern - SSR-safe hydrate() pattern for localStorage access - Frontend builds successfully with Svelte 5 runes
2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
var S=t=>{throw TypeError(t)};var c=(t,e,i)=>e.has(t)||S("Cannot "+i);var s=(t,e,i)=>(c(t,e,"read from private field"),i?i.call(t):e.get(t)),n=(t,e,i)=>e.has(t)?S("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i);import{h as d,g,e as h,u as _}from"./CqqhLxdp.js";const o={PB_TOKEN:"pb_token",SESSION:"auth_session"};var a,r,l,u;class f{constructor(){n(this,a,d(null));n(this,r,d(!0));n(this,l,_(()=>this._session!==null));n(this,u,_(()=>this._session?{email:this._session.email,displayName:this._session.displayName}:null))}get _session(){return g(s(this,a))}set _session(e){h(s(this,a),e,!0)}get _loading(){return g(s(this,r))}set _loading(e){h(s(this,r),e,!0)}get isAuthenticated(){return g(s(this,l))}set isAuthenticated(e){h(s(this,l),e)}get session(){return this._session}get loading(){return this._loading}get user(){return g(s(this,u))}set user(e){h(s(this,u),e)}hydrate(){if(typeof localStorage>"u")return;const e=localStorage.getItem(o.SESSION);if(e)try{this._session=JSON.parse(e)}catch{localStorage.removeItem(o.SESSION),localStorage.removeItem(o.PB_TOKEN)}this._loading=!1}login(e){typeof localStorage<"u"&&(localStorage.setItem(o.SESSION,JSON.stringify(e)),localStorage.setItem(o.PB_TOKEN,e.pbToken)),this._session=e,this._loading=!1}logout(){typeof localStorage<"u"&&(localStorage.removeItem(o.SESSION),localStorage.removeItem(o.PB_TOKEN)),this._session=null}redirectToLogin(){typeof window<"u"&&(window.location.href="/auth/login")}}a=new WeakMap,r=new WeakMap,l=new WeakMap,u=new WeakMap;const I=new f;export{I as a};
|