fix: move auth collection after config fetch — lexical scope bug
This commit is contained in:
parent
4a9266e249
commit
ef41c29981
1 changed files with 7 additions and 9 deletions
|
|
@ -383,6 +383,12 @@ document.getElementById('btn-save').addEventListener('click', async () => {
|
|||
});
|
||||
|
||||
try {
|
||||
// Fetch current config.
|
||||
const cr = await fetch(API + '/config');
|
||||
const cj = await cr.json();
|
||||
const cfg = cj.data || {};
|
||||
cfg.cameras = updatedCameras;
|
||||
|
||||
// Include auth settings from the management card.
|
||||
const authEnabled = document.querySelector('[data-auth="auth-enabled"]')?.checked || false;
|
||||
const masterUser = document.querySelector('[data-auth="master-user"]')?.value || '';
|
||||
|
|
@ -393,20 +399,12 @@ document.getElementById('btn-save').addEventListener('click', async () => {
|
|||
|
||||
cfg.auth = cfg.auth || {};
|
||||
cfg.auth.enabled = authEnabled;
|
||||
cfg.auth.master = cfg.auth.master || {};
|
||||
cfg.auth.master.username = masterUser;
|
||||
cfg.auth.viewer = cfg.auth.viewer || {};
|
||||
cfg.auth.viewer.username = viewerUser;
|
||||
cfg.auth.viewer.enabled = viewerEnabled || false;
|
||||
if (masterPass) { cfg.auth.master.password = masterPass; cfg.auth.master.enabled = true; }
|
||||
if (viewerPass) { cfg.auth.viewer.password = viewerPass; }
|
||||
|
||||
// Fetch current config, then post updated version.
|
||||
const cr = await fetch(API + '/config');
|
||||
const cj = await cr.json();
|
||||
const cfg = cj.data || {};
|
||||
cfg.cameras = updatedCameras;
|
||||
|
||||
const r = await fetch(API + '/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
|
|
|||
Loading…
Reference in a new issue