authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
1 lines • 1.26 kB
JavaScript
import {c,g as g$1}from'./chunk-5VQXQYKM.mjs';import {g}from'./chunk-TQPPJTEW.mjs';export{i as getCurrentUser,h as getCurrentUserFromToken,k as isAuthenticated,j as isTokenValid,f as logout,e as logoutCore,d as signin,c as signinCore,b as signup,a as signupCore}from'./chunk-TQPPJTEW.mjs';import'./chunk-ML66D24Y.mjs';import'./chunk-2W6WDMNG.mjs';import {a}from'./chunk-ZNCUQ2DE.mjs';export{a as authConfig,d as getAuthrixStatus,b as initAuth,c as isAuthrixInitialized}from'./chunk-ZNCUQ2DE.mjs';import'./chunk-3SAEGOMQ.mjs';async function C(i,d,n){try{let e=i.cookies[a.cookieName];if(!e)throw new c("Authentication required");let c$1=g(e),s=a.db;if(!s)throw new g$1("Database not configured");let o=await s.findUserById(c$1.id);if(!o)throw d.clearCookie(a.cookieName),new c("User not found");i.user={id:o.id,email:o.email},n();}catch(e){n(e);}}async function U(i,d,n){try{let e=i.cookies[a.cookieName];if(!e)throw new c("Authentication token is missing.");let c$1=g(e),s=a.db;if(!s)throw new g$1("Database not configured.");let o=await s.findUserById(c$1.id);if(!o)throw d.clearCookie(a.cookieName),new c("User not found or token is invalid.");i.user={id:o.id,email:o.email,createdAt:o.createdAt},n();}catch(e){n(e);}}export{U as authMiddleware,C as requireAuth};