Files
synapbus/internal/api/session_middleware.go
T
Algis DumbrisandClaude Opus 4.6 cad0138337 chore: migrate to github.com/synapbus org and add logo assets
Move module path from github.com/smart-mcp-proxy/synapbus to
github.com/synapbus/synapbus across all Go imports (47 files).
Add constellation logo options generated via FLUX 1.1 Pro.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 05:46:46 +02:00

26 lines
831 B
Go

package api
import (
"net/http"
"github.com/synapbus/synapbus/internal/auth"
)
// SessionToOwnerMiddleware wraps RequireSession and extracts the owner ID
// into the API context so that API handlers can use OwnerIDFromContext.
func SessionToOwnerMiddleware(userStore auth.UserStore, sessionStore auth.SessionStore) func(http.Handler) http.Handler {
sessionMW := auth.RequireSession(userStore, sessionStore)
return func(next http.Handler) http.Handler {
return sessionMW(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, ok := auth.UserFromContext(r.Context())
if !ok {
http.Error(w, `{"error":"unauthorized","message":"Authentication required"}`, http.StatusUnauthorized)
return
}
ctx := ContextWithOwnerID(r.Context(), user.ID)
next.ServeHTTP(w, r.WithContext(ctx))
}))
}
}