feat: implement next redirect flow, remove inactivity auto-logout, and add concurrent session termination notification
All checks were successful
Staging Build / build (push) Successful in 2m14s
All checks were successful
Staging Build / build (push) Successful in 2m14s
This commit is contained in:
@@ -25,20 +25,7 @@ export function InactivityTracker() {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const INACTIVITY_LIMIT = 5 * 60 * 1000; // 5 Minuten in ms
|
||||
|
||||
const updateActivity = () => {
|
||||
localStorage.setItem("last_activity", Date.now().toString());
|
||||
};
|
||||
|
||||
// Events zum Tracken der Benutzerinteraktion
|
||||
const events = ["mousemove", "keydown", "mousedown", "touchstart", "scroll", "click"];
|
||||
events.forEach((event) => window.addEventListener(event, updateActivity));
|
||||
|
||||
// Aktivitätszeitstempel beim Mounten initialisieren
|
||||
updateActivity();
|
||||
|
||||
// Regelmäßige Überprüfung der Inaktivität
|
||||
// Regelmäßige Überprüfung der Session-Gültigkeit (z.B. wegen Login auf anderem Browser/Gerät)
|
||||
const interval = setInterval(async () => {
|
||||
const { data: { session } } = await supabase.auth.getSession();
|
||||
if (!session) return; // Nicht eingeloggt, keine Prüfung nötig
|
||||
@@ -49,32 +36,15 @@ export function InactivityTracker() {
|
||||
try {
|
||||
await signOut();
|
||||
} catch (e) {
|
||||
console.error("Fehler beim Inactivity-Server-Signout:", e);
|
||||
console.error("Fehler beim Server-Signout nach Session-Verlust:", e);
|
||||
}
|
||||
await supabase.auth.signOut();
|
||||
localStorage.removeItem("last_activity");
|
||||
router.push("/");
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
const lastActivity = Number(localStorage.getItem("last_activity") || Date.now());
|
||||
if (Date.now() - lastActivity > INACTIVITY_LIMIT) {
|
||||
// Bei Überschreitung abmelden
|
||||
try {
|
||||
await signOut();
|
||||
} catch (e) {
|
||||
console.error("Fehler beim Inactivity-Server-Signout:", e);
|
||||
}
|
||||
await supabase.auth.signOut();
|
||||
localStorage.removeItem("last_activity");
|
||||
router.push("/");
|
||||
router.push("/auth/login?message=concurrent");
|
||||
router.refresh();
|
||||
}
|
||||
}, 5000); // Prüfung alle 5 Sekunden
|
||||
|
||||
return () => {
|
||||
events.forEach((event) => window.removeEventListener(event, updateActivity));
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [supabase, router]);
|
||||
|
||||
Reference in New Issue
Block a user