Files
klz-cables.com/.pnpm-store/v10/files/cb/ace3a338d020b7c47941d3fe450fbd9c35b8df87ad2cf3cf2fd487270fe655e01fc2664ef5dadbdaa3752e8d7d3232adae3ce87c54e362203932ebe74e71c1
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

78 lines
2.4 KiB
Plaintext

import { Forbidden } from '../../errors/index.js';
import { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js';
import { commitTransaction } from '../../utilities/commitTransaction.js';
import { initTransaction } from '../../utilities/initTransaction.js';
import { killTransaction } from '../../utilities/killTransaction.js';
import { ensureUsernameOrEmail } from '../ensureUsernameOrEmail.js';
export const registerFirstUserOperation = async (args)=>{
const { collection: { config, config: { slug, auth: { verify } } }, data, req, req: { payload } } = args;
if (config.auth.disableLocalStrategy) {
throw new Forbidden(req.t);
}
try {
const shouldCommit = await initTransaction(req);
ensureUsernameOrEmail({
authOptions: config.auth,
collectionSlug: slug,
data,
operation: 'create',
req
});
const where = appendNonTrashedFilter({
enableTrash: Boolean(config.trash),
trash: false,
where: {}
});
const doc = await payload.db.findOne({
collection: config.slug,
req,
where
});
if (doc) {
throw new Forbidden(req.t);
}
// /////////////////////////////////////
// Register first user
// /////////////////////////////////////
const result = await payload.create({
collection: slug,
data,
overrideAccess: true,
req
});
// auto-verify (if applicable)
if (verify) {
await payload.update({
id: result.id,
collection: slug,
data: {
_verified: true
},
req
});
}
// /////////////////////////////////////
// Log in new user
// /////////////////////////////////////
const { exp, token } = await payload.login({
...args,
collection: slug,
req
});
result.collection = slug;
result._strategy = 'local-jwt';
if (shouldCommit) {
await commitTransaction(req);
}
return {
exp,
token,
user: result
};
} catch (error) {
await killTransaction(req);
throw error;
}
};
//# sourceMappingURL=registerFirstUser.js.map