fix(auth): allow read-only access for non-disabled tokens

This commit is contained in:
CaIon
2026-07-05 13:35:10 +08:00
parent 5fc35e28a2
commit 0d5995eb63
+11
View File
@@ -274,6 +274,17 @@ func TokenAuthReadOnly() func(c *gin.Context) {
return
}
// TokenAuthReadOnly must keep allowing other token states to query read-only
// data, such as token usage logs; only explicitly disabled tokens are denied.
if token.Status == common.TokenStatusDisabled {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"message": common.TranslateMessage(c, i18n.MsgTokenStatusUnavailable),
})
c.Abort()
return
}
userCache, err := model.GetUserCache(token.UserId)
if err != nil {
common.SysLog(fmt.Sprintf("TokenAuthReadOnly GetUserCache error for user %d: %v", token.UserId, err))