Add a noauto query param to login

1cda7003d1441769239ea06042ccf945aec23286

QuantumEntangledAndy <sheepchaan@gmail.com>

Signed
3 files changed, +27 -10Ignore whitespace
public/scripts/login.js+7 -1
@@ -180,7 +180,13 @@ function displayError(message) {
180 * Preserves the query string.180 * Preserves the query string.
181 */181 */
182function redirectToHome() {182function 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();
184}190}
185191
186/**192/**
public/scripts/user.js+8 -1
@@ -848,7 +848,14 @@ async function logout() {
848 headers: getRequestHeaders(),848 headers: getRequestHeaders(),
849 });849 });
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();
852}859}
853860
854/**861/**
src/users.js+12 -8
@@ -569,6 +569,7 @@ function shouldRedirectToLogin(request) {
569569
570/**570/**
571 * Tries auto-login if there is only one user and it's not password protected.571 * Tries auto-login if there is only one user and it's not password protected.
572 * or another configured method such authlia or basic
572 * @param {import('express').Request} request Request object573 * @param {import('express').Request} request Request object
573 * @returns {Promise<boolean>} Whether auto-login was performed574 * @returns {Promise<boolean>} Whether auto-login was performed
574 */575 */
@@ -577,16 +578,19 @@ async function tryAutoLogin(request) {
577 return false;578 return false;
578 }579 }
579580
580 if (await singleUserLogin(request)) {581 console.warn(request.session.noauto);
581 return true;582 if (!request.query.noauto) {
582 }583 if (await singleUserLogin(request)) {
584 return true;
585 }
583586
584 if (AUTHELIA_AUTH && await autheliaUserLogin(request)) {587 if (AUTHELIA_AUTH && await autheliaUserLogin(request)) {
585 return true;588 return true;
586 }589 }
587590
588 if (PERUSER_BASIC_AUTH && await basicUserLogin(request)) {591 if (PERUSER_BASIC_AUTH && await basicUserLogin(request)) {
589 return true;592 return true;
593 }
590 }594 }
591595
592 return false;596 return false;