var h=Object.defineProperty;var y=(n,t,e)=>t in n?h(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var o=(n,t,e)=>(y(n,typeof t!="symbol"?t+"":t,e),e);import{S as c,q as d}from"./outputWidgets.d94fff8c.js";import{P as l}from"./pubsub.39314a92.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[t]="f79c9f8f-0c31-4764-9538-79c5994f0799",n._sentryDebugIdIdentifier="sentry-dbid-f79c9f8f-0c31-4764-9538-79c5994f0799")}catch{}})();const a=class{constructor(t,e){this.providerConfig=t,this.userManager=e}static async init(t,e){a.instance=new a(t,e)}get provider(){return this.providerConfig.provider}async authenticate(t){try{const e=await fetch(`${this.providerConfig.authority}/authenticate`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t})});if(!e.ok)throw new Error(await e.text());return null}catch(e){return e.message}}async verify(t,e){const u=await fetch(`${this.providerConfig.authority}/verify`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t,token:e})});if(!u.ok)return null;const f=await u.json();return this.userManager.saveJWT(f.jwt),this.userManager.getUser()}};let r=a;o(r,"instance",null);const s=class{constructor(t=new l){this.pubsub=t}saveJWT(t){c.set(s.key,t),this.notify()}notify(){const t=this.getUser();this.pubsub.publish("authenticated",t)}getJWT(){return c.get(s.key)}getUser(){const t=this.getJWT();if(t)try{const e=d(t);if(e.exp&&e.exp>Date.now()/1e3)return{jwt:t,claims:e}}catch{console.warn("Invalid JWT")}return null}removeUser(){this.pubsub.publish("authenticated",null),c.remove(s.key)}};let i=s;o(i,"key","abstra:auth:jwt");const p=new i;async function v(){const n=await fetch("/_auth/config");if(!n.ok)throw new Error(await n.text());const t=await n.json();await r.init(t,p)}export{r as A,p as a,v as u};
//# sourceMappingURL=index.7a77fb2c.js.map
