@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.39 kB
JavaScript
import{copy as e}from"../../i18n/copy.mjs";import t from"../../../utils/errors/lucid-api-error.mjs";import{multiTenancyEnabled as n}from"../../../utils/helpers/tenants.mjs";import r from"../utils/create-service-context.mjs";import{decodeApiKey as i}from"../../../utils/client-integrations/encode-api-key.mjs";import a from"../../../services/client-integrations/update-last-used.mjs";import o from"../../../services/client-integrations/verify-api-key.mjs";import s from"../../../utils/services/service-wrapper.mjs";import{createMiddleware as c}from"hono/factory";const l=c(async(c,l)=>{let u=c.req.header(`Authorization`),d=c.get(`runtimeContext`).getConnectionInfo(c),f=c.req.header(`user-agent`)||null,p=r(c);if(!u)throw new t({type:`authorisation`,message:e(`server:core.client.integrations.api.key.missing`),status:401});let{key:m}=i(u);if(!m)throw new t({message:e(`server:core.client.integrations.key.missing`)});let h=await s(o,{transaction:!1,defaultError:{type:`authorisation`,message:e(`server:core.client.integrations.error`),status:401}})(p,{apiKey:u});if(h.error)throw new t(h.error);let g=n(c.get(`config`))?h.data.tenantKey:null;c.set(`clientIntegrationAuth`,h.data),c.set(`tenant`,g?{key:g}:null);let _=await l();return a(p,{id:h.data.id,ipAddress:d.address??null,userAgent:f}).catch(()=>void 0),_});export{l as default};
//# sourceMappingURL=client-authenticate.mjs.map