fix: treat guest as unauthenticated in user state

This commit is contained in:
OpenClaw Agent
2026-09-22 04:50:44 +08:00
parent 7b2c5f444b
commit 73c05ef112
+8 -1
View File
@@ -563,7 +563,14 @@ func (s *Server) me(w http.ResponseWriter, r *http.Request) {
writeJSONError(w, http.StatusUnauthorized, "not authenticated")
return
}
writeJSON(w, map[string]any{"username": a.Username, "home": a.Home, "admin": a.Admin, "mask": permString(a.MaskFor(a.Home)), "managed": a.PasswordHash != "", "enabled": a.Enabled})
// The anonymous account is an authorization identity, not a logged-in user.
// Keep its internal username for permission matching, but expose an empty
// username to the UI so an initial visit is correctly shown as "访客".
username := a.Username
if a == s.Auth.Guest {
username = ""
}
writeJSON(w, map[string]any{"username": username, "home": a.Home, "admin": a.Admin, "mask": permString(a.MaskFor(a.Home)), "managed": a.PasswordHash != "", "enabled": a.Enabled})
}
type accessibleRoot struct {