2026-05-20 23:51:22 +00:00
|
|
|
package member
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type actorKey struct{}
|
|
|
|
|
|
2026-05-21 06:45:35 +00:00
|
|
|
// Actor identifies the calling member (JWT middleware or dev headers).
|
2026-05-20 23:51:22 +00:00
|
|
|
type Actor struct {
|
|
|
|
|
TenantID string
|
|
|
|
|
UID string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithActor stores tenant/uid on the context for member logic handlers.
|
|
|
|
|
func WithActor(ctx context.Context, tenantID, uid string) context.Context {
|
|
|
|
|
return context.WithValue(ctx, actorKey{}, Actor{TenantID: tenantID, UID: uid})
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 06:45:35 +00:00
|
|
|
// ActorFromContext reads the member actor injected by JWT middleware or dev headers.
|
2026-05-20 23:51:22 +00:00
|
|
|
func ActorFromContext(ctx context.Context) (Actor, error) {
|
|
|
|
|
v, ok := ctx.Value(actorKey{}).(Actor)
|
|
|
|
|
if !ok || v.TenantID == "" || v.UID == "" {
|
2026-05-21 06:45:35 +00:00
|
|
|
return Actor{}, fmt.Errorf("missing bearer token or X-Tenant-ID/X-UID headers")
|
2026-05-20 23:51:22 +00:00
|
|
|
}
|
|
|
|
|
return v, nil
|
|
|
|
|
}
|