-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-user-data.html
More file actions
92 lines (79 loc) · 3.27 KB
/
debug-user-data.html
File metadata and controls
92 lines (79 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>调试用户数据</title>
<style>
body { font-family: Arial; max-width: 800px; margin: 0 auto; padding: 20px; }
pre { background: #f5f5f5; padding: 20px; border-radius: 5px; overflow: auto; }
button { padding: 10px 20px; margin: 10px 0; cursor: pointer; }
</style>
</head>
<body>
<h1>调试用户数据</h1>
<button onclick="fetchUserData()">获取用户数据</button>
<button onclick="checkDatabaseData()">检查数据库数据</button>
<h2>原始响应数据:</h2>
<pre id="rawData">点击按钮获取数据...</pre>
<h2>解析后的字段:</h2>
<pre id="parsedData"></pre>
<script>
async function fetchUserData() {
const token = localStorage.getItem('token');
if (!token) {
document.getElementById('rawData').textContent = '没有找到 token';
return;
}
try {
const response = await fetch('http://localhost:3001/api/auth/me', {
headers: {
'Authorization': `Bearer ${token}`
}
});
const data = await response.json();
// 显示原始数据
document.getElementById('rawData').textContent = JSON.stringify(data, null, 2);
// 解析字段
if (data.user) {
const user = data.user;
const parsed = `
用户字段分析:
- id: ${user.id}
- username: ${user.username}
- email: ${user.email}
- displayName: ${user.displayName} (是否存在: ${user.displayName !== undefined})
- display_name: ${user.display_name} (是否存在: ${user.display_name !== undefined})
- role: ${user.role}
- department: ${user.department}
- larkUserId: ${user.larkUserId} (是否存在: ${user.larkUserId !== undefined})
- lark_user_id: ${user.lark_user_id} (是否存在: ${user.lark_user_id !== undefined})
- isActive: ${user.isActive} (是否存在: ${user.isActive !== undefined})
- is_active: ${user.is_active} (是否存在: ${user.is_active !== undefined})
所有字段:
${Object.keys(user).join(', ')}
`;
document.getElementById('parsedData').textContent = parsed;
}
} catch (error) {
document.getElementById('rawData').textContent = '错误: ' + error.message;
}
}
async function checkDatabaseData() {
// 直接查看数据库中的原始数据
const token = localStorage.getItem('token');
// 解码 JWT token 获取用户 ID
if (token) {
const parts = token.split('.');
const payload = JSON.parse(atob(parts[1]));
document.getElementById('parsedData').textContent = `
Token 内容:
${JSON.stringify(payload, null, 2)}
用户 ID: ${payload.id}
`;
}
}
// 页面加载时自动获取
window.onload = fetchUserData;
</script>
</body>
</html>