fix: enhance API key handling and logging in middleware

Refactor API key processing to improve clarity and reduce code 
duplication. Introduce detailed logging for schema updates and 
initializations, capturing relevant context information. Use 
background context for async operations to avoid blocking. 
Implement organization lookup logic in the WebSocket init 
function for consistent API key handling across connections.
This commit is contained in:
2025-11-20 08:09:00 +01:00
parent a9a47c1690
commit bb0c08be06
3 changed files with 69 additions and 6 deletions
+3 -1
View File
@@ -49,7 +49,9 @@ func (m *AuthMiddleware) Handler(next http.Handler) http.Handler {
_, _ = w.Write([]byte("Invalid API Key format"))
return
}
if organization := m.cache.OrganizationByAPIKey(hash.String(apiKey)); organization != nil {
hashedKey := hash.String(apiKey)
organization := m.cache.OrganizationByAPIKey(hashedKey)
if organization != nil {
ctx = context.WithValue(ctx, OrganizationKey, *organization)
}