diff --git a/static/js/features/auth/auth.js b/static/js/features/auth/auth.js index c6982468..d52b223e 100644 --- a/static/js/features/auth/auth.js +++ b/static/js/features/auth/auth.js @@ -729,9 +729,25 @@ if (isLoginPage && adminSetupForm) { } try { - // Register admin account - const data = await register('admin', email, password, 'admin'); - + // Use the /api/setup endpoint which creates an admin and marks the system as initialized + const setupToken = document.getElementById('admin-setup-token').value; + const response = await fetch('/api/setup', { + method: 'POST', + headers: { 'Content-Type': 'application/json', ...getCsrfHeaders() }, + credentials: 'same-origin', + body: JSON.stringify({ + username: 'admin', + email, + password, + setup_token: setupToken + }) + }); + if (!response.ok) { + const err = await response.json().catch(() => ({})); + throw new Error(err.message || 'Setup failed'); + } + const data = await response.json(); + // Show success message in the GUI instead of alert const successMsg = window.i18n ? window.i18n.t('auth.admin_success') : 'Admin account created successfully! You can now log in.'; diff --git a/static/login.html b/static/login.html index 936947a2..76e2ba97 100644 --- a/static/login.html +++ b/static/login.html @@ -273,6 +273,19 @@ > +