68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
|
|
async function verifyFirstUser() {
|
|
const prisma = new PrismaClient();
|
|
|
|
try {
|
|
console.log('🔍 验证首位用户权限设置...\n');
|
|
|
|
const users = await prisma.user.findMany({
|
|
orderBy: { createdAt: 'asc' }
|
|
});
|
|
|
|
console.log(`📊 用户总数: ${users.length}`);
|
|
|
|
if (users.length === 0) {
|
|
console.log('❌ 用户表为空,请先注册一个用户');
|
|
return;
|
|
}
|
|
|
|
const firstUser = users[0];
|
|
console.log('\n👤 首位用户信息:');
|
|
console.log(` 邮箱: ${firstUser.email}`);
|
|
console.log(` 用户名: ${firstUser.username || '未设置'}`);
|
|
console.log(` 角色: ${firstUser.role}`);
|
|
console.log(` 超级管理员: ${firstUser.isSuperAdmin ? '✅ 是' : '❌ 否'}`);
|
|
console.log(` 激活状态: ${firstUser.isActive ? '✅ 已激活' : '❌ 未激活'}`);
|
|
console.log(` 创建时间: ${firstUser.createdAt.toLocaleString()}`);
|
|
|
|
// 验证首位用户是否符合预期规则
|
|
const isFirstUserCorrect =
|
|
firstUser.role === 'ADMIN' &&
|
|
firstUser.isSuperAdmin === true &&
|
|
firstUser.isActive === true;
|
|
|
|
console.log('\n🎯 权限验证结果:');
|
|
if (isFirstUserCorrect) {
|
|
console.log('✅ 首位用户权限设置完全正确!');
|
|
console.log(` 符合"首位注册用户默认为超级用户"的规则 (共${users.length}个用户)`);
|
|
console.log('\n🔗 您现在可以:');
|
|
console.log(' 1. 访问管理后台: /admin');
|
|
console.log(' 2. 管理所有系统设置');
|
|
console.log(' 3. 邀请其他用户并分配权限');
|
|
console.log(' 4. 使用超级用户权限管理整个系统');
|
|
} else {
|
|
console.log('❌ 首位用户权限设置有误:');
|
|
if (firstUser.role !== 'ADMIN') console.log(' - 角色不是 ADMIN');
|
|
if (firstUser.isSuperAdmin !== true) console.log(' - 不是超级管理员');
|
|
if (firstUser.isActive !== true) console.log(' - 用户未激活');
|
|
}
|
|
|
|
// 显示所有用户状态概览
|
|
console.log('\n📋 所有用户状态:');
|
|
users.forEach((user, index) => {
|
|
const isFirst = index === 0;
|
|
const status = user.isActive ? '✅' : '❌';
|
|
const adminStatus = user.isSuperAdmin ? '🏆' : '👤';
|
|
const role = user.role === 'ADMIN' ? '管理员' : '用户';
|
|
console.log(` ${index + 1}. ${user.email} ${adminStatus} ${role} ${status} ${isFirst ? '(首位用户)' : ''}`);
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('❌ 验证时出错:', error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
verifyFirstUser(); |