mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
fix: 修复用户菜单显示问题和真实用户名显示
- 修复登录接口返回真实用户名而非输入用户名 - 新增获取当前用户信息的API接口(/web/auth/user) - 修复前端用户名显示逻辑,页面初始化时获取真实用户名 - 提高下拉菜单z-index确保正确显示 - 解决用户名显示为Admin而非data/init.json中真实用户名的问题 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -114,7 +114,8 @@ router.post('/auth/login', async (req, res) => {
|
||||
res.json({
|
||||
success: true,
|
||||
token: sessionId,
|
||||
expiresIn: config.security.adminSessionTimeout
|
||||
expiresIn: config.security.adminSessionTimeout,
|
||||
username: adminData.username // 返回真实用户名
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
@@ -252,6 +253,54 @@ router.post('/auth/change-password', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 👤 获取当前用户信息
|
||||
router.get('/auth/user', async (req, res) => {
|
||||
try {
|
||||
const token = req.headers['authorization']?.replace('Bearer ', '') || req.cookies?.adminToken;
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({
|
||||
error: 'No token provided',
|
||||
message: 'Authentication required'
|
||||
});
|
||||
}
|
||||
|
||||
// 获取当前会话
|
||||
const sessionData = await redis.getSession(token);
|
||||
if (!sessionData) {
|
||||
return res.status(401).json({
|
||||
error: 'Invalid token',
|
||||
message: 'Session expired or invalid'
|
||||
});
|
||||
}
|
||||
|
||||
// 获取管理员信息
|
||||
const adminData = await redis.getSession('admin_credentials');
|
||||
if (!adminData) {
|
||||
return res.status(500).json({
|
||||
error: 'Admin data not found',
|
||||
message: 'Administrator credentials not found'
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
user: {
|
||||
username: adminData.username,
|
||||
loginTime: sessionData.loginTime,
|
||||
lastActivity: sessionData.lastActivity
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('❌ Get user info error:', error);
|
||||
res.status(500).json({
|
||||
error: 'Get user info failed',
|
||||
message: 'Internal server error'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 🔄 刷新token
|
||||
router.post('/auth/refresh', async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user