fix login
Deploy / deploy (push) Successful in 8s

This commit is contained in:
2026-05-06 12:07:39 +02:00
parent c940864c60
commit 40f9fda3e6
2 changed files with 41 additions and 20 deletions
+20 -18
View File
@@ -368,32 +368,35 @@ async function checkAuth() {
initApp();
return true;
}
if (res.error) {
if (res.login_url) {
showLogin(res.error, res.login_url);
} else if (res.error) {
showLogin(res.error);
return false;
}
} catch (e) {
try {
const err = JSON.parse(e.message);
showLogin(err.error);
} catch {
} else {
showLogin();
}
return false;
} catch (e) {
if (e.login_url) {
showLogin('Session expired. Please log in again.', e.login_url);
} else {
showLogin('Cannot connect to server: ' + e.message);
}
}
showLogin();
return false;
}
function showLogin(errorMsg) {
function showLogin(errorMsg, loginUrl) {
document.getElementById('appLogin').style.display = '';
document.getElementById('appMain').style.display = 'none';
const loginUrl = window.location.origin + '/oauth.php?redirect=' + encodeURIComponent(window.location.href);
document.getElementById('loginBtn').href = 'https://auth.jakach.ch/?send_to=' + encodeURIComponent(loginUrl);
const cbUrl = window.location.origin + '/oauth.php?redirect=' + encodeURIComponent(window.location.href);
const href = loginUrl || ('https://auth.jakach.ch/?send_to=' + encodeURIComponent(cbUrl));
document.getElementById('loginBtn').href = href;
const errorBox = document.getElementById('authErrorBox');
if (errorMsg) {
errorBox.textContent = errorMsg;
errorBox.classList.remove('d-none');
document.getElementById('loginBtn').textContent = 'Try again';
document.getElementById('loginBtn').innerHTML = '<i class="bi bi-box-arrow-in-right me-2"></i>Try again';
} else {
errorBox.classList.add('d-none');
document.getElementById('loginBtn').innerHTML = '<i class="bi bi-box-arrow-in-right me-2"></i>Log in using Jakach Login';
@@ -444,11 +447,10 @@ async function api(path, opts = {}) {
});
const data = await res.json();
if (!res.ok) {
if (res.status === 401 && data.login_url) {
window.location.href = data.login_url;
return;
}
throw new Error(data.error || 'Request failed');
const err = new Error(data.error || 'Request failed');
err.login_url = data.login_url;
err.status = res.status;
throw err;
}
return data;
}