Refactor redirectToHome function to use URL object

e753e432be61fe6c79f2879ce2e7c20086254486

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -5Ignore whitespace
public/scripts/login.js+10 -5
@@ -180,13 +180,18 @@ function displayError(message) {
180 * Preserves the query string.180 * Preserves the query string.
181 */181 */
182function redirectToHome() {182function redirectToHome() {
183 // After a login theres no need to preserve the183 // Create a URL object based on the current location
184 // noauto (if present)184 const currentUrl = new URL(window.location.href);
185 const urlParams = new URLSearchParams(window.location.search);
186185
187 urlParams.delete('noauto');186 // After a login there's no need to preserve the
187 // noauto parameter (if present)
188 currentUrl.searchParams.delete('noauto');
188189
189 window.location.href = '/' + urlParams.toString();190 // Set the pathname to root and keep the updated query string
191 currentUrl.pathname = '/';
192
193 // Redirect to the new URL
194 window.location.href = currentUrl.toString();
190}195}
191196
192/**197/**