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