1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

admin: fix logout when url base is used

two tries are made, with and without the url base.
This commit is contained in:
Harvey Tindall 2023-06-26 20:28:20 +01:00
parent 5a80145607
commit a13a72c626
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -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; }