diff --git a/internal/web/templates/admin.html b/internal/web/templates/admin.html index d2eb786..86f10ee 100644 --- a/internal/web/templates/admin.html +++ b/internal/web/templates/admin.html @@ -44,7 +44,8 @@ function api(path, opts) { opts = opts || {}; - opts.headers = { 'X-Admin-Key': key() }; + // allow callers to override the key header (e.g. validating a typed key, #99) + opts.headers = Object.assign({ 'X-Admin-Key': key() }, opts.headers || {}); if (opts.body) opts.headers['Content-Type'] = 'application/json'; return fetch(path, opts); } @@ -72,9 +73,10 @@ document.getElementById('admin-key-form').addEventListener('submit', function (e) { e.preventDefault(); - sessionStorage.setItem(KEY, keyInput.value); - api('/admin/api/settings').then(function (r) { + // #99: don't persist the key until the server accepts it + api('/admin/api/settings', { headers: { 'X-Admin-Key': keyInput.value } }).then(function (r) { if (r.status === 200) { + sessionStorage.setItem(KEY, keyInput.value); status.textContent = '✓'; keyInput.value = ''; loadSettings();