Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 13s
Build & Deploy / 🏗️ Build (push) Has been cancelled
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🧪 QA (push) Has been cancelled
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { getPayload } from 'payload';
|
|
import config from '../payload.config';
|
|
|
|
async function run() {
|
|
try {
|
|
const payload = await getPayload({ config: await config });
|
|
const user = await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: 'agent@mintel.me',
|
|
password: 'agentpassword123',
|
|
},
|
|
});
|
|
console.log('SUCCESS: Created AI Agent admin user', user.id);
|
|
} catch (e) {
|
|
if (
|
|
e.message?.includes('duplicate key') ||
|
|
e.code === '11000' ||
|
|
String(e).includes('already exists')
|
|
) {
|
|
console.log('User already exists, attempting to update password...', e.message);
|
|
const payload = await getPayload({ config: await config });
|
|
const users = await payload.find({
|
|
collection: 'users',
|
|
where: { email: { equals: 'agent@mintel.me' } },
|
|
});
|
|
if (users.docs.length > 0) {
|
|
await payload.update({
|
|
collection: 'users',
|
|
id: users.docs[0].id,
|
|
data: { password: 'agentpassword123' },
|
|
});
|
|
console.log('SUCCESS: Updated existing AI Agent admin user password');
|
|
}
|
|
} else {
|
|
console.error('ERROR creating user:', e);
|
|
}
|
|
}
|
|
process.exit(0);
|
|
}
|
|
run();
|