From a13a72c626e434f916af2beab576c229b95ee5fe Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 26 Jun 2023 20:28:20 +0100 Subject: [PATCH] admin: fix logout when url base is used two tries are made, with and without the url base. --- ts/modules/login.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ts/modules/login.ts b/ts/modules/login.ts index c9248c4..1527e10 100644 --- a/ts/modules/login.ts +++ b/ts/modules/login.ts @@ -5,11 +5,12 @@ export class Login { private _modal: Modal; private _form: HTMLFormElement; private _url: string; + private _endpoint: string; private _onLogin: (username: string, password: string) => void; private _logoutButton: HTMLElement = null; constructor(modal: Modal, endpoint: string) { - + this._endpoint = endpoint; this._url = window.URLBase + endpoint; if (this._url[this._url.length-1] != '/') this._url += "/"; @@ -32,13 +33,21 @@ export class Login { bindLogout = (button: HTMLElement) => { this._logoutButton = button; this._logoutButton.classList.add("unfocused"); - this._logoutButton.onclick = () => _post(this._url + "logout", null, (req: XMLHttpRequest): boolean => { - if (req.readyState == 4 && req.status == 200) { - window.token = ""; - location.reload(); - return false; - } - }); + const logoutFunc = (url: string, tryAgain: boolean) => { + _post(url + "logout", null, (req: XMLHttpRequest): boolean => { + if (req.readyState == 4 && req.status == 200) { + window.token = ""; + location.reload(); + return false; + } + }, false, (req: XMLHttpRequest) => { + if (req.readyState == 4 && req.status == 404 && tryAgain) { + console.log("trying without URL Base..."); + logoutFunc(this._endpoint, false); + } + }); + }; + this._logoutButton.onclick = () => logoutFunc(this._url, true); }; get onLogin() { return this._onLogin; }