punimtag/viewer-frontend/scripts/manually-verify-user.ts
Tanya de2144be2a feat: Add new scripts and update project structure for database management and user authentication
This commit introduces several new scripts for managing database operations, including user creation, permission grants, and data migrations. It also adds new documentation files to guide users through the setup and configuration processes. Additionally, the project structure is updated to enhance organization and maintainability, ensuring a smoother development experience for contributors. These changes support the ongoing transition to a web-based architecture and improve overall project functionality.
2026-01-06 13:53:24 -05:00

76 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PrismaClient as PrismaClientAuth } from '../node_modules/.prisma/client-auth';
import * as dotenv from 'dotenv';
dotenv.config();
const prismaAuth = new PrismaClientAuth({
datasourceUrl: process.env.DATABASE_URL_AUTH,
});
async function manuallyVerifyUser() {
try {
console.log('🔍 Finding unverified users...\n');
const unverifiedUsers = await prismaAuth.user.findMany({
where: {
emailVerified: false,
},
select: {
id: true,
email: true,
name: true,
createdAt: true,
},
orderBy: {
createdAt: 'desc',
},
});
if (unverifiedUsers.length === 0) {
console.log('✅ No unverified users found.');
return;
}
console.log(`Found ${unverifiedUsers.length} unverified user(s):\n`);
unverifiedUsers.forEach((user, index) => {
console.log(`${index + 1}. ${user.email} (${user.name}) - Created: ${user.createdAt}`);
});
// Verify all unverified users
console.log('\n✅ Verifying all unverified users...\n');
for (const user of unverifiedUsers) {
await prismaAuth.user.update({
where: { id: user.id },
data: {
emailVerified: true,
emailConfirmationToken: null,
emailConfirmationTokenExpiry: null,
},
});
console.log(`✅ Verified: ${user.email} (${user.name})`);
}
console.log('\n🎉 All users have been verified! They can now log in.');
} catch (error: any) {
console.error('❌ Error:', error.message);
if (error.message?.includes('email_verified')) {
console.error('\n⚠ Database migration may not have been run!');
console.error(' Run: sudo -u postgres psql -d punimtag_auth -f migrations/add-email-verification-columns.sql');
}
process.exit(1);
} finally {
await prismaAuth.$disconnect();
}
}
manuallyVerifyUser();