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.
76 lines
1.9 KiB
TypeScript
76 lines
1.9 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 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();
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|