From 4d7f8eda9c282d5193f772519d346ce45d0e14b5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 24 Oct 2023 22:11:15 +0200 Subject: [PATCH] Fix TOTP input field not being shown when enabled Signed-off-by: DL6ER --- scripts/pi-hole/js/login.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/login.js b/scripts/pi-hole/js/login.js index ef1ff70f..29afcf13 100644 --- a/scripts/pi-hole/js/login.js +++ b/scripts/pi-hole/js/login.js @@ -111,10 +111,16 @@ $(function () { // Check if we need to login at all $.ajax({ url: "/api/auth", - }).done(function (data) { - if (data.session.valid === true) redirect(); - if (data.session.totp === true) $("#totp_input").removeClass("hidden"); - }); + }) + .done(function (data) { + // If we are already logged in, redirect to dashboard + if (data.session.valid === true) redirect(); + }) + .fail(function (xhr) { + const session = xhr.responseJSON.session; + // If TOPT is enabled, show the input field + if (session.totp === true) $("#totp_input").removeClass("hidden"); + }); // Get information about HTTPS port and DNS status $.ajax({