feat: 添加 /api/auth/me 调试端点查看当前用户权限
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
kkfluous
2026-04-02 16:44:41 +08:00
parent 09719f3cd6
commit 4cd76b6a30

View File

@@ -78,4 +78,18 @@ app.get('/exchange', async (c) => {
}
});
/** GET /api/auth/me — 查看当前用户信息(调试用) */
app.get('/me', async (c) => {
const authHeader = c.req.header('Authorization');
if (!authHeader?.startsWith('Bearer ')) {
return c.json({ error: 'No token' }, 401);
}
try {
const payload = jwt.verify(authHeader.slice(7), JWT_SECRET) as JwtPayload;
return c.json(payload);
} catch {
return c.json({ error: 'Invalid token' }, 401);
}
});
export default app;