UNPKG

astro-kinde

Version:

Astro integration module for Kinde authentication

2 lines 645 B
import{defineMiddleware as k}from"astro/middleware";import f from"virtual:kinde-integration/config";function i(n){return n.headers.get("cookie")?.split("; ").find(e=>e.startsWith("kinde_access_token="))?.split("=")[1]}var h=k(async(n,t)=>{let{request:e,locals:o}=n,s=new URL(e.url);if(s.pathname.startsWith("/api/kinde/"))return s.pathname.startsWith("/api/kinde/signout")&&(o.accessToken=void 0),t();let r=i(e);r&&(o.accessToken=r);let a=e.headers.get("cookie"),c=await fetch(`${s.origin}/api/kinde/isAuthenticated`,{headers:{cookie:a||""}});return o.isAuthenticated=c.ok,t()});export{h as onRequest}; //# sourceMappingURL=authMiddleware.js.map