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
- Remove obsolete documentation files - Update .env_example - Update ManageUsers components - Update pending_photos API - Add verify-all-users script
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
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();
|
||
|