import{ae as i,ab as a,af as s,ag as n}from"./index-p1BAR2Hc.js";let e=null;const c=i("web-auth",{state:()=>({profile:JSON.parse(localStorage.getItem("web_profile")||"null"),account:null,authenticated:!!localStorage.getItem("web_access_token"),loading:!1}),actions:{async login(t,l){this.loading=!0;try{const{data:o}=await a.post("/auth/login",{account:t,password:l});n(o.data),this.profile=o.data.user,this.authenticated=!0,await this.loadAccount()}finally{this.loading=!1}},async loadAccount(){this.authenticated&&(e||(e=a.get("/account").then(({data:t})=>t.data).finally(()=>e=null)),this.account=await e)},updateCachedProfile(t){this.profile&&(this.profile={...this.profile,...t},localStorage.setItem("web_profile",JSON.stringify(this.profile)))},async logout(){const t=localStorage.getItem("web_refresh_token");try{await a.post("/auth/logout",{refresh_token:t})}finally{s(),this.profile=null,this.account=null,this.authenticated=!1}}}});export{c as u};