143 lines
4.4 KiB
JavaScript
143 lines
4.4 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
|
|
async function debugNextAuth() {
|
|
const prisma = new PrismaClient();
|
|
|
|
try {
|
|
console.log('=== NextAuth.js 调试信息 ===\n');
|
|
|
|
// 1. 检查当前数据库连接
|
|
console.log('1. 数据库连接信息:');
|
|
console.log(' 数据库URL:', process.env.DATABASE_URL);
|
|
|
|
// 2. 检查系统设置
|
|
console.log('\n2. 系统设置检查:');
|
|
const settings = await prisma.systemSettings.findFirst();
|
|
if (settings) {
|
|
console.log(' - 用户激活功能启用:', settings.enableUserActivation);
|
|
console.log(' - 系统设置存在');
|
|
} else {
|
|
console.log(' - 未找到系统设置');
|
|
}
|
|
|
|
// 3. 检查所有用户
|
|
console.log('\n3. 用户表完整检查:');
|
|
const allUsers = await prisma.user.findMany({
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
username: true,
|
|
role: true,
|
|
isSuperAdmin: true,
|
|
isActive: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
loginType: true,
|
|
dingtalkUserId: true,
|
|
},
|
|
orderBy: {
|
|
createdAt: 'desc'
|
|
}
|
|
});
|
|
|
|
console.log(` 总用户数: ${allUsers.length}`);
|
|
|
|
if (allUsers.length > 0) {
|
|
console.log(' 用户详情:');
|
|
allUsers.forEach((user, index) => {
|
|
console.log(` ${index + 1}. ID: ${user.id}`);
|
|
console.log(` 邮箱: ${user.email}`);
|
|
console.log(` 用户名: ${user.username}`);
|
|
console.log(` 角色: ${user.role}`);
|
|
console.log(` 是否超级管理员: ${user.isSuperAdmin}`);
|
|
console.log(` 是否激活: ${user.isActive}`);
|
|
console.log(` 是否已删除: ${user.deletedAt ? '是' : '否'}`);
|
|
console.log(` 创建时间: ${user.createdAt}`);
|
|
console.log(` 更新时间: ${user.updatedAt}`);
|
|
console.log('');
|
|
});
|
|
} else {
|
|
console.log(' 未找到任何用户记录');
|
|
}
|
|
|
|
// 4. 专门查找目标用户
|
|
console.log('\n4. 目标用户检查 (549727955@qq.com):');
|
|
const targetUser = await prisma.user.findMany({
|
|
where: {
|
|
email: '549727955@qq.com'
|
|
},
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
username: true,
|
|
role: true,
|
|
isSuperAdmin: true,
|
|
isActive: true,
|
|
createdAt: true,
|
|
loginType: true,
|
|
dingtalkUserId: true,
|
|
}
|
|
});
|
|
|
|
if (targetUser.length > 0) {
|
|
console.log(' 找到目标用户:');
|
|
targetUser.forEach(user => {
|
|
console.log(` - ID: ${user.id}`);
|
|
console.log(` - 邮箱: ${user.email}`);
|
|
console.log(` - 角色: ${user.role}`);
|
|
console.log(` - 是否超级管理员: ${user.isSuperAdmin}`);
|
|
console.log(` - 是否激活: ${user.isActive}`);
|
|
console.log(` - 登录类型: ${user.loginType || 'normal'}`);
|
|
console.log(` - 钉钉用户ID: ${user.dingtalkUserId || '无'}`);
|
|
});
|
|
} else {
|
|
console.log(' 未找到目标用户记录');
|
|
}
|
|
|
|
// 5. 检查是否有其他相关数据表
|
|
console.log('\n5. 其他数据表检查:');
|
|
|
|
try {
|
|
// 检查钉钉相关表
|
|
const dingtalkUsers = await prisma.$queryRaw`
|
|
SELECT COUNT(*) as count FROM information_schema.tables
|
|
WHERE table_schema = DATABASE() AND table_name LIKE '%dingtalk%'
|
|
`;
|
|
console.log(' - 钉钉相关表数量:', dingtalkUsers[0]?.count || 0);
|
|
} catch (error) {
|
|
console.log(' - 钉钉表检查失败:', error.message);
|
|
}
|
|
|
|
// 6. 检查最近的操作日志(如果有的话)
|
|
console.log('\n6. 数据库操作历史检查:');
|
|
const recentActivity = await prisma.$queryRaw`
|
|
SELECT
|
|
schemaname,
|
|
tablename,
|
|
query,
|
|
query_start
|
|
FROM pg_stat_statements
|
|
WHERE query LIKE '%user%' OR query LIKE '%549727955%'
|
|
ORDER BY query_start DESC
|
|
LIMIT 5
|
|
`;
|
|
|
|
if (recentActivity.length > 0) {
|
|
console.log(' 最近的数据库操作:');
|
|
recentActivity.forEach((activity, index) => {
|
|
console.log(` ${index + 1}. ${activity.query_start}: ${activity.query.substring(0, 100)}...`);
|
|
});
|
|
} else {
|
|
console.log(' 未找到相关操作历史');
|
|
}
|
|
|
|
console.log('\n=== 调试完成 ===');
|
|
|
|
} catch (error) {
|
|
console.error('调试过程中出现错误:', error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
debugNextAuth(); |