feat: redesign superadmin agencies list, implement flat design, add date filters, and fix UI bugs
This commit is contained in:
@@ -40,17 +40,33 @@ func Auth(cfg *config.Config) func(http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
claims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
http.Error(w, "Invalid token claims", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
claims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok {
|
||||
http.Error(w, "Invalid token claims", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
userID := claims["user_id"].(string)
|
||||
tenantID := claims["tenant_id"].(string)
|
||||
ctx := context.WithValue(r.Context(), UserIDKey, userID)
|
||||
ctx = context.WithValue(ctx, TenantIDKey, tenantID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
// Verificar se user_id existe e é do tipo correto
|
||||
userIDClaim, ok := claims["user_id"]
|
||||
if !ok || userIDClaim == nil {
|
||||
http.Error(w, "Missing user_id in token", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
userID, ok := userIDClaim.(string)
|
||||
if !ok {
|
||||
http.Error(w, "Invalid user_id format in token", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// tenant_id pode ser nil para SuperAdmin
|
||||
var tenantID string
|
||||
if tenantIDClaim, ok := claims["tenant_id"]; ok && tenantIDClaim != nil {
|
||||
tenantID, _ = tenantIDClaim.(string)
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), UserIDKey, userID)
|
||||
ctx = context.WithValue(ctx, TenantIDKey, tenantID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user