mirror of
https://github.com/hyzendust/hyzendust.github.io.git
synced 2026-07-01 07:22:17 +02:00
Fix: redirect login/signup
This commit is contained in:
@@ -93,6 +93,38 @@
|
||||
(function () {
|
||||
var BACKEND = 'https://backend.freedoms4.org/auth.php';
|
||||
|
||||
// ── Already logged in ──
|
||||
if (localStorage.getItem('f4_username')) {
|
||||
document.getElementById('auth-message').textContent = 'You are already logged in!';
|
||||
document.getElementById('auth-message').className =
|
||||
'auth-message auth-message--success';
|
||||
document.getElementById('auth-message').style.display = 'block';
|
||||
document.getElementById('login-form').style.display = 'none';
|
||||
setTimeout(function () {
|
||||
window.location.href = '/';
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// ── Remember where to go after login ──
|
||||
(function () {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var next = params.get('next');
|
||||
if (next && next.startsWith('/')) {
|
||||
sessionStorage.setItem('f4_login_next', next);
|
||||
} else if (!sessionStorage.getItem('f4_login_next') && document.referrer) {
|
||||
try {
|
||||
var refUrl = new URL(document.referrer);
|
||||
if (refUrl.hostname === window.location.hostname) {
|
||||
var p = refUrl.pathname;
|
||||
if (p !== '/login/' && p !== '/signup/') {
|
||||
sessionStorage.setItem('f4_login_next', p);
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
})();
|
||||
|
||||
var form = document.getElementById('login-form');
|
||||
var msgBox = document.getElementById('auth-message');
|
||||
var submitBtn = document.getElementById('login-submit');
|
||||
@@ -142,7 +174,10 @@
|
||||
showMsg('Logged in successfully! Redirecting\u2026', 'success');
|
||||
localStorage.setItem('f4_username', username);
|
||||
setTimeout(function () {
|
||||
window.location.href = data.redirect || '/';
|
||||
var _next = sessionStorage.getItem('f4_login_next');
|
||||
sessionStorage.removeItem('f4_login_next');
|
||||
window.location.href =
|
||||
_next && _next.startsWith('/') ? _next : data.redirect || '/';
|
||||
}, 1000);
|
||||
} else {
|
||||
showMsg(data.message || 'Login failed. Please try again.', 'error');
|
||||
|
||||
Reference in New Issue
Block a user