UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.89 kB
import{copy as e}from"../../../libs/i18n/copy.mjs";import t from"../../../utils/helpers/get-base-url.mjs";import n from"../../../libs/repositories/auth-states.mjs";import r from"../../../libs/auth-providers/get-available-providers.mjs";import i from"../../../libs/auth-providers/get-adapter.mjs";import a from"../../../libs/auth-providers/helpers/build-callback-redirect-url.mjs";import o from"./helpers/process-provider-auth.mjs";const s=async(s,c)=>{let l=new n(s.db.client,s.config.db),u=r(s.config).providers.find(e=>e.key===c.providerKey);if(!u)return{error:{type:`basic`,status:404,name:e(`server:core.auth.providers.not.found.name`),message:e(`server:core.auth.providers.not.found.message`)},data:void 0};let d=await l.selectSingle({select:[`id`,`provider_key`,`invitation_token_id`,`redirect_path`,`action_type`,`authenticated_user_id`],where:[{key:`state`,operator:`=`,value:c.state},{key:`expiry_date`,operator:`>`,value:new Date().toISOString()},{key:`provider_key`,operator:`=`,value:c.providerKey}],validation:{enabled:!0,defaultError:{status:400,message:e(`server:core.invalid.or.expired.state.message`)}}});if(d.error)return d;let f=i(u);if(f.error)return f;let p=await f.data.handleCallback({code:c.code,state:c.state,redirectUri:a(t(s),c.providerKey)});if(p.error)return p;let[m]=await Promise.all([o(s,{providerKey:c.providerKey,providerUserId:p.data.userId,firstName:p.data.firstName,lastName:p.data.lastName,invitationTokenId:d.data.invitation_token_id??void 0,redirectPath:d.data.redirect_path??void 0,actionType:d.data.action_type??void 0,authenticatedUserId:d.data.authenticated_user_id??void 0}),l.deleteSingle({where:[{key:`id`,operator:`=`,value:d.data.id}]})]);return m.error?m:{error:void 0,data:{userId:m.data.userId,redirectUrl:m.data.redirectUrl,grantAuthentication:m.data.grantAuthentication}}};export{s as default}; //# sourceMappingURL=oidc-callback.mjs.map