authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
1 lines • 1.51 kB
JavaScript
import {a,c,e,h,j}from'./chunk-TQPPJTEW.mjs';import {a as a$1}from'./chunk-ZNCUQ2DE.mjs';async function k(r,e){try{return await a(r,e)}catch(t){return {success:false,error:{message:t instanceof Error?t.message:"Unknown error"}}}}async function A(r,e){try{return await c(r,e)}catch(t){return {success:false,error:{message:t instanceof Error?t.message:"Unknown error"}}}}function d(){return e()}async function C(r){return h(r)}async function y(r){return j(r)}function R(r,e,t){let n=`${r}=${e}`;return t.maxAge&&(n+=`; Max-Age=${t.maxAge}`),t.expires&&(n+=`; Expires=${t.expires.toUTCString()}`),t.path&&(n+=`; Path=${t.path}`),t.secure&&(n+="; Secure"),t.httpOnly&&(n+="; HttpOnly"),t.sameSite&&(n+=`; SameSite=${t.sameSite}`),n}function S(r){let e={};return r&&r.split(";").forEach(t=>{let[n,...g]=t.split("="),s=g.join("=");n&&s&&(e[n.trim()]=s.trim());}),e}function U(r){return r[a$1.cookieName]||null}async function v(r){try{if(!r)return {isValid:!1,user:null,error:"No token provided"};let e=await h(r);return e?{isValid:!0,user:e,error:null}:{isValid:!1,user:null,error:"Invalid or expired token"}}catch(e){return {isValid:false,user:null,error:e instanceof Error?e.message:"Authentication failed"}}}function O(r){return {Authorization:`Bearer ${r}`,"Content-Type":"application/json"}}function E(r,e=401){return {success:false,error:{message:r},status:e}}function T(r,e=200){return {success:true,data:r,status:e}}export{k as a,A as b,d as c,C as d,y as e,R as f,S as g,U as h,v as i,O as j,E as k,T as l};