morz-infoboard/server/backend/internal/reqcontext/reqcontext.go
Jesko Anschütz 27c4562175 Tenant-Feature Phase 3b: Login-Redirect + Tenant-Context in Manage-UI
- reqcontext-Package: shared contextKey für httpapi und manage
- Login-Redirect: Tenant-User → /manage/<slug>, Admin → /admin
- GetUserByUsername: LEFT JOIN tenants für TenantSlug-Befüllung
- manage/ui.go: reqcontext.UserFromContext statt hardcoded "morz"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 18:00:02 +01:00

26 lines
799 B
Go

// Package reqcontext provides a shared context key and helpers for storing
// the authenticated user in a request context. It lives in its own package so
// that both httpapi (middleware) and httpapi/manage (handlers) can import it
// without creating an import cycle.
package reqcontext
import (
"context"
"git.az-it.net/az/morz-infoboard/server/backend/internal/store"
)
type contextKey int
const contextKeyUser contextKey = 0
// WithUser returns a new context that carries u.
func WithUser(ctx context.Context, u *store.User) context.Context {
return context.WithValue(ctx, contextKeyUser, u)
}
// UserFromContext returns the *store.User stored in ctx, or nil if none.
func UserFromContext(ctx context.Context) *store.User {
u, _ := ctx.Value(contextKeyUser).(*store.User)
return u
}