65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
#!/usr/bin/env tsx
|
|
/**
|
|
* Quick script to set admin password using the app's database connection
|
|
* Works with runtime DATABASE_URL from environment
|
|
*/
|
|
|
|
// Use the same db module as the app
|
|
import { prisma } from '../src/lib/db';
|
|
import { hash } from 'bcryptjs';
|
|
|
|
async function main() {
|
|
const username = process.argv[2] || 'admin';
|
|
const newPassword = process.argv[3] || 'TSD107AS';
|
|
|
|
console.log(`\n🔐 Setting admin password...`);
|
|
console.log(` Username: ${username}`);
|
|
console.log(` Password: ${newPassword}\n`);
|
|
|
|
try {
|
|
// Hash the password
|
|
const hashedPassword = await hash(newPassword, 10);
|
|
|
|
// Check if admin exists
|
|
const existingAdmin = await prisma.admin.findUnique({
|
|
where: { username },
|
|
});
|
|
|
|
if (existingAdmin) {
|
|
// Update existing admin
|
|
await prisma.admin.update({
|
|
where: { username },
|
|
data: {
|
|
password: hashedPassword,
|
|
},
|
|
});
|
|
console.log(`✅ Updated password for admin user: ${username}`);
|
|
} else {
|
|
// Create new admin
|
|
await prisma.admin.create({
|
|
data: {
|
|
username,
|
|
password: hashedPassword,
|
|
email: 'admin@themoyos.co.za',
|
|
},
|
|
});
|
|
console.log(`✅ Created new admin user: ${username}`);
|
|
}
|
|
|
|
console.log('\n📋 Login Credentials:');
|
|
console.log(` Username: ${username}`);
|
|
console.log(` Password: ${newPassword}`);
|
|
console.log('\n✅ Password set successfully!\n');
|
|
} catch (error) {
|
|
console.error('❌ Error:', error);
|
|
if (error instanceof Error) {
|
|
console.error(' Message:', error.message);
|
|
}
|
|
process.exit(1);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
main();
|