punimtag/viewer-frontend/scripts/verify-all-users.ts
tanyar09 6688a654d3
Some checks failed
CI / skip-ci-check (pull_request) Successful in 8s
CI / python-lint (pull_request) Has been cancelled
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / lint-and-type-check (pull_request) Has been cancelled
chore: Clean up documentation and update various files
- Remove obsolete documentation files
- Update .env_example
- Update ManageUsers components
- Update pending_photos API
- Add verify-all-users script
2026-01-29 19:52:48 +00:00

66 lines
1.8 KiB
TypeScript
Raw Permalink 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 verifyAllUsers() {
try {
console.log('🔍 Finding all users...\n');
const allUsers = await prismaAuth.user.findMany({
select: {
id: true,
email: true,
name: true,
emailVerified: true,
createdAt: true,
},
orderBy: {
createdAt: 'desc',
},
});
if (allUsers.length === 0) {
console.log('✅ No users found.');
return;
}
console.log(`Found ${allUsers.length} user(s):\n`);
allUsers.forEach((user, index) => {
const status = user.emailVerified ? '✅ Verified' : '❌ Unverified';
console.log(`${index + 1}. ${user.email} (${user.name}) - ${status} - Created: ${user.createdAt}`);
});
// Verify all users
console.log('\n✅ Verifying all users (force confirm)...\n');
const result = await prismaAuth.user.updateMany({
data: {
emailVerified: true,
emailConfirmationToken: null,
emailConfirmationTokenExpiry: null,
},
});
console.log(`✅ Successfully verified ${result.count} user(s)!`);
console.log('\n🎉 All users can now log in without email verification.');
} 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();
}
}
verifyAllUsers();