var b=Object.defineProperty;var y=(r,e,t)=>e in r?b(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var d=(r,e,t)=>(y(r,typeof e!="symbol"?e+"":e,t),t);import{ep as l}from"./registerWidgets.92d2f644.js";import{P as g}from"./pubsub.cabffe13.js";import{S as u}from"./storage.63ab52ef.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[e]="ca59eb2e-4861-4af8-bac5-cd8fe77d8b45",r._sentryDebugIdIdentifier="sentry-dbid-ca59eb2e-4861-4af8-bac5-cd8fe77d8b45")}catch{}})();const m=()=>window.location.host.includes(".abstra.io"),v={passwordless:"/api/passwordless","cloud-api":"/api/cloud-api"},E={passwordless:"https://passwordless.abstra.cloud","cloud-api":"https://cloud-api.abstra.cloud"},w=r=>{const e="VITE_"+l.toUpper(l.snakeCase(r)),t={VITE_SENTRY_RELEASE:"99e77fc10ad89c9f217f18a6d94868a2a138ba1d",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}[e];return t||(m()?v[r]:E[r])};function p(r){this.message=r}p.prototype=new Error,p.prototype.name="InvalidCharacterError";var h=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(r){var e=String(r).replace(/=+$/,"");if(e.length%4==1)throw new p("'atob' failed: The string to be decoded is not correctly encoded.");for(var t,n,s=0,o=0,f="";n=e.charAt(o++);~n&&(t=s%4?64*t+n:n,s++%4)?f+=String.fromCharCode(255&t>>(-2*s&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return f};function k(r){var e=r.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(h(t).replace(/(.)/g,function(n,s){var o=s.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o}))}(e)}catch{return h(e)}}function c(r){this.message=r}function I(r,e){if(typeof r!="string")throw new c("Invalid token specified");var t=(e=e||{}).header===!0?0:1;try{return JSON.parse(k(r.split(".")[t]))}catch(n){throw new c("Invalid token specified: "+n.message)}}c.prototype=new Error,c.prototype.name="InvalidTokenError";const a=class{constructor(){d(this,"pubsub");this.pubsub=new g}async authenticate(e){try{const t=await fetch(`${w("passwordless")}/authenticate`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:e})});if(!t.ok)throw new Error(await t.text());return null}catch(t){return t.message}}async verify(e,t){const n=await fetch(`${w("passwordless")}/verify`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:e,token:t})});if(!n.ok)throw new Error(await n.text());const s=await n.json();this.saveJWT(s.jwt);const o=this.getUser();return this.pubsub.publish("authenticated",o),o}saveJWT(e){u.set(a.key,e)}getJWT(){return u.get(a.key)}getUser(){const e=this.getJWT();if(e)try{const t=I(e);if(t.exp&&t.exp>Date.now()/1e3)return{jwt:e,claims:t}}catch{console.warn("Invalid JWT")}return null}removeUser(){u.remove(a.key)}getUserHeaders(e="User-Authorization"){const t=this.getJWT();return t?{[e]:`Bearer ${t}`}:{}}};let i=a;d(i,"key","hackerforms:auth:jwt");const R=new i;export{R as p,w as t};
//# sourceMappingURL=passwordlessManager.d1484834.js.map
