fix: unify tenant context keys and load tenant_id from JWT
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
type contextKey string
|
||||
|
||||
const UserIDKey contextKey = "userID"
|
||||
const TenantIDKey contextKey = "tenantID"
|
||||
|
||||
// Auth validates JWT tokens
|
||||
func Auth(cfg *config.Config) func(http.Handler) http.Handler {
|
||||
@@ -46,7 +47,9 @@ func Auth(cfg *config.Config) func(http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import (
|
||||
"aggios-app/backend/internal/repository"
|
||||
)
|
||||
|
||||
type tenantContextKey string
|
||||
|
||||
const TenantIDKey tenantContextKey = "tenantID"
|
||||
const SubdomainKey tenantContextKey = "subdomain"
|
||||
const SubdomainKey contextKey = "subdomain"
|
||||
|
||||
// TenantDetector detects tenant from subdomain
|
||||
func TenantDetector(tenantRepo *repository.TenantRepository) func(http.Handler) http.Handler {
|
||||
|
||||
Reference in New Issue
Block a user