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>
26 lines
831 B
Go
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))
|
|
}))
|
|
}
|
|
}
|