diff --git a/shared/backend/mediaauth/auth.go b/shared/backend/mediaauth/auth.go index aeb095e..76d3504 100644 --- a/shared/backend/mediaauth/auth.go +++ b/shared/backend/mediaauth/auth.go @@ -531,17 +531,27 @@ func (s *Service) UpdateAccessSettings(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusBadRequest, "loginRequired must be a boolean") return } - if _, err := s.db.Exec(r.Context(), ` - INSERT INTO settings (key, value, updated_at) - VALUES ($1, $2, NOW()) - ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW() - `, loginRequiredSettingKey, strconv.FormatBool(*input.LoginRequired)); err != nil { + if err := s.SetLoginRequired(r.Context(), *input.LoginRequired); err != nil { writeError(w, http.StatusInternalServerError, "access setting could not be saved") return } writeJSON(w, http.StatusOK, map[string]bool{"loginRequired": *input.LoginRequired}) } +// SetLoginRequired writes the auth_required flag directly, the same one UpdateAccessSettings +// exposes to a manager-authenticated session - callers reach this from an X-Internal-Auth-gated +// route instead (see each service's own setLoginRequiredInternal), letting ProjectConfigurator's +// central "Require Login" toggle (ConfigWorkspace.svelte's loginControls) apply here without an +// admin session of its own. +func (s *Service) SetLoginRequired(ctx context.Context, required bool) error { + _, err := s.db.Exec(ctx, ` + INSERT INTO settings (key, value, updated_at) + VALUES ($1, $2, NOW()) + ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW() + `, loginRequiredSettingKey, strconv.FormatBool(required)) + return err +} + func (s *Service) Status(w http.ResponseWriter, r *http.Request) { if !s.enabled() { user := localProfile