authrix
Version:
Lightweight, flexible authentication library for Node.js and TypeScript.
1 lines • 2.75 kB
JavaScript
;var chunkCUSEWHH4_cjs=require('./chunk-CUSEWHH4.cjs'),chunkPTWJCNT6_cjs=require('./chunk-PTWJCNT6.cjs');require('./chunk-RUOJ57HW.cjs'),require('./chunk-O5GBK76P.cjs');var chunkIRGTWVM7_cjs=require('./chunk-IRGTWVM7.cjs');require('./chunk-D6WM53FN.cjs');async function C(i,d,n){try{let e=i.cookies[chunkIRGTWVM7_cjs.a.cookieName];if(!e)throw new chunkCUSEWHH4_cjs.c("Authentication required");let c=chunkPTWJCNT6_cjs.g(e),s=chunkIRGTWVM7_cjs.a.db;if(!s)throw new chunkCUSEWHH4_cjs.g("Database not configured");let o=await s.findUserById(c.id);if(!o)throw d.clearCookie(chunkIRGTWVM7_cjs.a.cookieName),new chunkCUSEWHH4_cjs.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[chunkIRGTWVM7_cjs.a.cookieName];if(!e)throw new chunkCUSEWHH4_cjs.c("Authentication token is missing.");let c=chunkPTWJCNT6_cjs.g(e),s=chunkIRGTWVM7_cjs.a.db;if(!s)throw new chunkCUSEWHH4_cjs.g("Database not configured.");let o=await s.findUserById(c.id);if(!o)throw d.clearCookie(chunkIRGTWVM7_cjs.a.cookieName),new chunkCUSEWHH4_cjs.c("User not found or token is invalid.");i.user={id:o.id,email:o.email,createdAt:o.createdAt},n();}catch(e){n(e);}}Object.defineProperty(exports,"getCurrentUser",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.i}});Object.defineProperty(exports,"getCurrentUserFromToken",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.h}});Object.defineProperty(exports,"isAuthenticated",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.k}});Object.defineProperty(exports,"isTokenValid",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.j}});Object.defineProperty(exports,"logout",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.f}});Object.defineProperty(exports,"logoutCore",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.e}});Object.defineProperty(exports,"signin",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.d}});Object.defineProperty(exports,"signinCore",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.c}});Object.defineProperty(exports,"signup",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.b}});Object.defineProperty(exports,"signupCore",{enumerable:true,get:function(){return chunkPTWJCNT6_cjs.a}});Object.defineProperty(exports,"authConfig",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.a}});Object.defineProperty(exports,"getAuthrixStatus",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.d}});Object.defineProperty(exports,"initAuth",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.b}});Object.defineProperty(exports,"isAuthrixInitialized",{enumerable:true,get:function(){return chunkIRGTWVM7_cjs.c}});exports.authMiddleware=U;exports.requireAuth=C;