Files

51 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

/**
* Dev helper: reset password for a password-auth user.
* Usage: npx tsx scripts/reset-user-password.ts <email> <newPassword>
*/
import { prisma } from '../src/lib/prisma.ts';
import { hashPassword } from '../src/modules/auth/password.ts';
const email = process.argv[2]?.trim().toLowerCase();
const nextPassword = process.argv[3];
if (!email || !nextPassword) {
console.error('Usage: npx tsx scripts/reset-user-password.ts <email> <newPassword>');
process.exit(1);
}
if (nextPassword.length < 8 || nextPassword.length > 128) {
console.error('Password must be 8–128 characters');
process.exit(1);
}
const identity = await prisma.authIdentity.findFirst({
where: {
provider: 'password',
OR: [{ email }, { providerSubject: email }],
},
});
if (!identity) {
console.error(`No password account found for ${email}`);
process.exit(1);
}
const passwordHash = await hashPassword(nextPassword);
await prisma.authIdentity.update({
where: { id: identity.id },
data: { passwordHash },
});
console.log(
JSON.stringify(
{
email: identity.email ?? identity.providerSubject,
passwordUpdated: true,
},
null,
2,
),
);
await prisma.$disconnect();