text: import{ref as e,computed as t,inject as n}from"vue";import s from"axios";
  /*! *****************************************************************************
  Copyright (c) Microsoft Corporation.
  
  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted.
  
  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  PERFORMANCE OF THIS SOFTWARE.
  ***************************************************************************** */function o(e,t,n,s){return new(n||(n=Promise))((function(o,r){function i(e){try{a(s.next(e))}catch(e){r(e)}}function c(e){try{a(s.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}a((s=s.apply(e,t||[])).next())}))}const r=Symbol("account");class i{constructor(e=""){this.ACCESS_TOKEN_KEY=`${e}access-token`,this.REFRESH_TOKEN_KEY=`${e}refresh-token`}setAccessToken(e){localStorage.setItem(this.ACCESS_TOKEN_KEY,e)}setRefreshToken(e){localStorage.setItem(this.REFRESH_TOKEN_KEY,e)}getAccessToken(){return localStorage.getItem(this.ACCESS_TOKEN_KEY)||""}getRefreshToken(){return localStorage.getItem(this.REFRESH_TOKEN_KEY)||""}destory(){localStorage.removeItem(this.ACCESS_TOKEN_KEY),localStorage.removeItem(this.REFRESH_TOKEN_KEY)}hasToken(){return this.getAccessToken()&&this.getRefreshToken()}}function c(n){var c;const a=n.baseURL,u=n.authBaseURL||"",h=n.onTokenExpire,f=new i(n.prefix),l=null!==(c=n.getAxiosInstance)&&void 0!==c?c:e=>s.create(e),d=n.injectionKey||r,T={baseURL:a,headers:{"Content-Type":"application/json"}},g=e=>`${u}${e}`,E=l(T),p=l(T),k=l(T);p.interceptors.request.use((e=>{const t=f.getAccessToken();return t&&(e.headers.Authorization="Bearer "+t),e})),p.interceptors.response.use((e=>e),(e=>e.response&&401===e.response.status?k.post(g("/refresh")).then((t=>{const n=t.data;return f.setAccessToken(n.accessToken),f.setRefreshToken(n.refreshToken),p(e.config)})):Promise.reject(e))),k.interceptors.request.use((e=>{const t=f.getRefreshToken();return t&&(e.headers.Authorization="Bearer "+t),e})),k.interceptors.response.use((e=>e),(e=>{if(!e.response||401!==e.response.status)throw e;f.destory(),h()}));const S=e();function v(){return o(this,void 0,void 0,(function*(){return yield p.get(g("/info")).then((e=>(S.value=e.data,e.data)))}))}return{get defaults(){return T},get isSignedIn(){return!!f.getAccessToken()&&!!f.getRefreshToken()},origin:E,access:p,refresh:k,user:t((()=>S.value)),signin:function(e,t){return o(this,void 0,void 0,(function*(){const n=yield E.post(g("/signin"),{username:e,password:t}),s=n.data;return f.setAccessToken(s.accessToken),f.setRefreshToken(s.refreshToken),yield v(),n.data}))},info:v,signout:function(){return o(this,void 0,void 0,(function*(){yield k.post(g("/signout"),{access:f.getAccessToken()}),f.destory()}))},changeInfo:function(e={}){return o(this,void 0,void 0,(function*(){return yield p.put("/info",e)}))},install(e){e.provide(d,this)}}}function a(e=null){return n(e||r)}export{c as createAccount,a as useAccount};
  