Files
klz-cables.com/.pnpm-store/v10/files/cd/5f0b66e05117b4cd70385095b4b99af3a8ecd6e55501a43f2f87c43efc79d1b68dab07a38055d756c245512f0be5033c233824a6f4bb5af76524770cb089cd
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

43 lines
1.8 KiB
Plaintext

import { ValidationError } from '../errors/index.js';
export const ensureUsernameOrEmail = ({ authOptions: { disableLocalStrategy, loginWithUsername }, collectionSlug, data, operation, originalDoc, req })=>{
// neither username or email are required
// and neither are provided
// so we need to manually validate
if (!disableLocalStrategy && loginWithUsername && !loginWithUsername.requireEmail && !loginWithUsername.requireUsername) {
let missingFields = false;
if (operation === 'create' && !data.email && !data.username) {
missingFields = true;
} else if (operation === 'update') {
// prevent clearing both email and username
if ('email' in data && !data.email && 'username' in data && !data.username) {
missingFields = true;
}
// prevent clearing email if no username
if ('email' in data && !data.email && !originalDoc.username && !data?.username) {
missingFields = true;
}
// prevent clearing username if no email
if ('username' in data && !data.username && !originalDoc.email && !data?.email) {
missingFields = true;
}
}
if (missingFields) {
throw new ValidationError({
collection: collectionSlug,
errors: [
{
message: 'Username or email is required',
path: 'username'
},
{
message: 'Username or email is required',
path: 'email'
}
]
}, req.t);
}
}
return;
};
//# sourceMappingURL=ensureUsernameOrEmail.js.map