Files
klz-cables.com/.pnpm-store/v10/files/06/948a257d0a7908535baa1ccb365342c4dff5ad570bc5ac5eabf59c82f6f525ae8cdb0b17d83ea904f144cfde9aabdc3c4e83dc4a035c1b9fd210ee0e382b93
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

77 lines
2.1 KiB
Plaintext

import { ValidationError } from '../../../errors/index.js';
import { getLoginOptions } from '../../getLoginOptions.js';
import { generatePasswordSaltHash } from './generatePasswordSaltHash.js';
export const registerLocalStrategy = async ({ collection, doc, password, payload, req })=>{
const loginWithUsername = collection?.auth?.loginWithUsername;
const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername);
let whereConstraint;
if (!canLoginWithUsername) {
whereConstraint = {
email: {
equals: doc.email
}
};
} else {
whereConstraint = {
or: []
};
if (canLoginWithEmail && doc.email) {
whereConstraint.or?.push({
email: {
equals: doc.email
}
});
}
if (doc.username) {
whereConstraint.or?.push({
username: {
equals: doc.username
}
});
}
}
const existingUser = await payload.find({
collection: collection.slug,
depth: 0,
limit: 1,
pagination: false,
req,
where: whereConstraint
});
if (existingUser.docs.length > 0) {
throw new ValidationError({
collection: collection.slug,
errors: [
canLoginWithUsername ? {
message: req.t('error:usernameAlreadyRegistered'),
path: 'username'
} : {
message: req.t('error:userEmailAlreadyRegistered'),
path: 'email'
}
]
});
}
const { hash, salt } = await generatePasswordSaltHash({
collection,
password,
req
});
const sanitizedDoc = {
...doc
};
if (sanitizedDoc.password) {
delete sanitizedDoc.password;
}
return payload.db.create({
collection: collection.slug,
data: {
...sanitizedDoc,
hash,
salt
},
req
});
};
//# sourceMappingURL=register.js.map