40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function resetPasswords() {
|
|
try {
|
|
// Password to set for all users
|
|
const newPassword = 'password123';
|
|
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
|
|
|
// Get all users
|
|
const users = await prisma.user.findMany();
|
|
|
|
console.log('Resetting passwords for all users...');
|
|
|
|
// Update each user's password
|
|
for (const user of users) {
|
|
await prisma.user.update({
|
|
where: { id: user.id },
|
|
data: {
|
|
password: hashedPassword,
|
|
isActive: true // Ensure all users are active
|
|
}
|
|
});
|
|
console.log(`✅ Reset password for ${user.email}`);
|
|
}
|
|
|
|
console.log('\nSemua password telah direset ke: password123');
|
|
console.log('Silakan login dengan email yang ada dan password: password123');
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
resetPasswords();
|