authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
1 lines • 2.08 kB
JavaScript
;var chunkIRGTWVM7_cjs=require('./chunk-IRGTWVM7.cjs');require('./chunk-D6WM53FN.cjs');function c(t){if(typeof document>"u")return null;let n=`; ${document.cookie}`.split(`; ${t}=`);return n.length===2&&n.pop()?.split(";").shift()||null}function l(t,e="/"){typeof document>"u"||(document.cookie=`${t}=; Path=${e}; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`);}async function g(t,e,n="/api/auth/signup"){let r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,password:e}),credentials:"include"});if(!r.ok){let i=await r.json();throw new Error(i.error?.message||"Signup failed")}return r.json()}async function f(t,e,n="/api/auth/signin"){let r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,password:e}),credentials:"include"});if(!r.ok){let i=await r.json();throw new Error(i.error?.message||"Signin failed")}return r.json()}async function h(t="/api/auth/logout"){let e=await fetch(t,{method:"POST",credentials:"include"});if(!e.ok){let n=await e.json();throw new Error(n.error?.message||"Logout failed")}return l(chunkIRGTWVM7_cjs.a.cookieName),e.json()}async function s(t="/api/auth/me"){try{let e=await fetch(t,{credentials:"include"});if(!e.ok){if(e.status===401)return null;throw new Error("Failed to get current user")}return (await e.json()).user||null}catch{return null}}async function p(t="/api/auth/me"){return await s(t)!==null}function a(){return c(chunkIRGTWVM7_cjs.a.cookieName)}function d(){return a()!==null}function m(){return function(){return a()}}function k(t={}){return function(e){return function(r){return null}}}Object.defineProperty(exports,"authConfig",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.a}});Object.defineProperty(exports,"initAuth",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.b}});exports.createUseAuthToken=m;exports.getAuthToken=a;exports.getCurrentUserReact=s;exports.hasAuthToken=d;exports.isAuthenticatedReact=p;exports.logoutReact=h;exports.signinReact=f;exports.signupReact=g;exports.withAuthReact=k;