var g=Object.defineProperty;var y=(r,t,e)=>t in r?g(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{t as h}from"./registerWidgets.4cc86716.js";const v=()=>window.location.host.includes(".abstra.io"),m={passwordless:"/api/passwordless","cloud-api":"/api/cloud-api"},b={passwordless:"https://passwordless.abstra.cloud","cloud-api":"https://cloud-api.abstra.cloud"},w=r=>{const t="VITE_"+h.toUpper(h.snakeCase(r)),e={BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}[t];return e||(v()?m[r]:b[r])};class s{static get(t){try{const e=localStorage.getItem(t);return e&&JSON.parse(e)}catch{return null}}static set(t,e){localStorage.setItem(t,JSON.stringify(e))}static pop(t){const e=s.get(t);return s.remove(t),e}static remove(t){localStorage.removeItem(t)}}function p(r){this.message=r}p.prototype=new Error,p.prototype.name="InvalidCharacterError";var f=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new p("'atob' failed: The string to be decoded is not correctly encoded.");for(var e,o,n=0,a=0,d="";o=t.charAt(a++);~o&&(e=n%4?64*e+o:o,n++%4)?d+=String.fromCharCode(255&e>>(-2*n&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return d};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(f(e).replace(/(.)/g,function(o,n){var a=n.charCodeAt(0).toString(16).toUpperCase();return a.length<2&&(a="0"+a),"%"+a}))}(t)}catch{return f(t)}}function l(r){this.message=r}function S(r,t){if(typeof r!="string")throw new l("Invalid token specified");var e=(t=t||{}).header===!0?0:1;try{return JSON.parse(k(r.split(".")[e]))}catch(o){throw new l("Invalid token specified: "+o.message)}}l.prototype=new Error,l.prototype.name="InvalidTokenError";const i=class{async authenticate(t){try{const e=await fetch(`${w("passwordless")}/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 o=await fetch(`${w("passwordless")}/verify`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t,token:e})});if(!o.ok)throw new Error(await o.text());const n=await o.json();return this.saveJWT(n.jwt),this.getUser()}saveJWT(t){s.set(i.key,t)}getJWT(){return s.get(i.key)}getUser(){const t=this.getJWT();if(t)try{const e=S(t);if(e.exp&&e.exp>Date.now()/1e3)return{jwt:t,claims:e}}catch{console.warn("Invalid JWT")}return null}removeUser(){s.remove(i.key)}getUserHeaders(t="User-Authorization"){const e=this.getJWT();return e?{[t]:`Bearer ${e}`}:{}}};let c=i;u(c,"key","hackerforms:auth:jwt");const E=new c;export{E as p,w as t};
//# sourceMappingURL=passwordlessManager.d432fb48.js.map
