@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.54 kB
JavaScript
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../constants/constants.mjs";import{decrypt as n}from"../../utils/helpers/encrypt-decrypt.mjs";import r from"../../libs/repositories/users.mjs";import{trimStringInput as i}from"../../utils/helpers/normalize-input.mjs";import a from"../../libs/formatters/index.mjs";import{scrypt as o}from"@noble/hashes/scrypt.js";const s=async(s,c)=>{if(s.config.auth.password.enabled===!1)return{error:{type:`basic`,status:400,message:e(`server:core.auth.password.authentication.disabled.message`)},data:void 0};let l=new r(s.db.client,s.config.db),u=i(c.usernameOrEmail),d=await l.selectSingleByEmailUsername({select:[`id`,`password`,`is_deleted`,`is_locked`,`secret`],where:{username:u,email:u.toLowerCase()},validation:{enabled:!0,defaultError:{type:`authorisation`,message:e(`server:core.auth.login.error.message`),status:401}}});if(d.error)return d;if(a.formatBoolean(d.data.is_deleted))return{error:{type:`authorisation`,message:e(`server:core.auth.login.suspended.error.message`),status:401},data:void 0};if(a.formatBoolean(d.data.is_locked))return{error:{type:`authorisation`,message:e(`server:core.auth.login.locked.error.message`),status:401},data:void 0};let f=n(d.data.secret,s.config.secrets.encryption);return Buffer.from(o(c.password,f,t.scrypt)).toString(`base64`)===d.data.password?{error:void 0,data:{id:d.data.id}}:{error:{type:`authorisation`,message:e(`server:core.auth.login.error.message`),status:401},data:void 0}};export{s as default};
//# sourceMappingURL=login.mjs.map