Aktueller Stand
This commit is contained in:
36
web/login.js
36
web/login.js
@@ -1,4 +1,5 @@
|
|||||||
const API_URL = 'https://fb.srv.medeba-media.de/api';
|
const API_URL = 'https://fb.srv.medeba-media.de/api';
|
||||||
|
const LOGIN_BROADCAST_KEY = 'fb-login-broadcast';
|
||||||
|
|
||||||
function getRedirectTarget() {
|
function getRedirectTarget() {
|
||||||
try {
|
try {
|
||||||
@@ -69,6 +70,7 @@ async function handleLogin(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateStatus('Erfolgreich angemeldet. Weiterleitung…', false);
|
updateStatus('Erfolgreich angemeldet. Weiterleitung…', false);
|
||||||
|
broadcastLogin();
|
||||||
window.location.href = getRedirectTarget();
|
window.location.href = getRedirectTarget();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Login fehlgeschlagen:', error);
|
console.error('Login fehlgeschlagen:', error);
|
||||||
@@ -82,8 +84,42 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupCrossTabLoginSync();
|
||||||
|
|
||||||
const form = document.getElementById('loginForm');
|
const form = document.getElementById('loginForm');
|
||||||
if (form) {
|
if (form) {
|
||||||
form.addEventListener('submit', handleLogin);
|
form.addEventListener('submit', handleLogin);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function broadcastLogin() {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(LOGIN_BROADCAST_KEY, String(Date.now()));
|
||||||
|
} catch (error) {
|
||||||
|
// ignore storage errors (private mode, blocked)
|
||||||
|
}
|
||||||
|
if ('BroadcastChannel' in window) {
|
||||||
|
try {
|
||||||
|
const channel = new BroadcastChannel('fb-login');
|
||||||
|
channel.postMessage({ type: 'login', at: Date.now() });
|
||||||
|
channel.close();
|
||||||
|
} catch (error) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupCrossTabLoginSync() {
|
||||||
|
window.addEventListener('storage', (event) => {
|
||||||
|
if (event.key !== LOGIN_BROADCAST_KEY) return;
|
||||||
|
checkExistingSession();
|
||||||
|
});
|
||||||
|
|
||||||
|
if ('BroadcastChannel' in window) {
|
||||||
|
const channel = new BroadcastChannel('fb-login');
|
||||||
|
channel.addEventListener('message', (event) => {
|
||||||
|
if (!event || !event.data || event.data.type !== 'login') return;
|
||||||
|
checkExistingSession();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user