Add a noauto query param to login

1cda7003d1441769239ea06042ccf945aec23286

QuantumEntangledAndy <sheepchaan@gmail.com>

Signed
3 files changed, +19 -2Showing whitespace changes
public/scripts/login.js+7 -1
@@ -180,7 +180,13 @@ function displayError(message) {
180180 * Preserves the query string.
181181 */
182182function redirectToHome() {
183- window.location.href = '/' + window.location.search;
183+ // After a login theres no need to preserve the
184+ // noauto (if present)
185+ const urlParams = new URLSearchParams(window.location.search);
186+
187+ urlParams.delete('noauto');
188+
189+ window.location.href = '/' + urlParams.toString();
184190}
185191
186192/**
public/scripts/user.js+8 -1
@@ -848,7 +848,14 @@ async function logout() {
848848 headers: getRequestHeaders(),
849849 });
850850
851- window.location.reload();
851+ // On an explicit logout stop auto login
852+ // to allow user to change username even
853+ // when auto auth (such as authelia or basic)
854+ // would be valid
855+ const urlParams = new URLSearchParams(window.location.search);
856+ urlParams.set('noauto', 'true');
857+
858+ window.location.search = urlParams.toString();
852859}
853860
854861/**
src/users.js+4 -0
@@ -569,6 +569,7 @@ function shouldRedirectToLogin(request) {
569569
570570/**
571571 * Tries auto-login if there is only one user and it's not password protected.
572+ * or another configured method such authlia or basic
572573 * @param {import('express').Request} request Request object
573574 * @returns {Promise<boolean>} Whether auto-login was performed
574575 */
@@ -577,6 +578,8 @@ async function tryAutoLogin(request) {
577578 return false;
578579 }
579580
581+ console.warn(request.session.noauto);
582+ if (!request.query.noauto) {
580583 if (await singleUserLogin(request)) {
581584 return true;
582585 }
@@ -588,6 +591,7 @@ async function tryAutoLogin(request) {
588591 if (PERUSER_BASIC_AUTH && await basicUserLogin(request)) {
589592 return true;
590593 }
594+ }
591595
592596 return false;
593597}