feat: add global auth listener with hard reload on logout

This commit is contained in:
2025-12-18 21:45:27 +01:00
parent 6f32bfa17f
commit 17727243be
2 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
'use client';
import { useEffect } from 'react';
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs';
export default function AuthListener() {
const supabase = createClientComponentClient();
useEffect(() => {
// Listener für Auth-Status Änderungen
const {
data: { subscription },
} = supabase.auth.onAuthStateChange((event) => {
if (event === 'SIGNED_OUT') {
console.log(`[Auth] Event ${event} detected, forcing reload...`);
// Zwinge den Browser zum kompletten Neuladen, um Caches zu leeren
// Wir nutzen window.location.href statt router.push für einen harten Reload
window.location.href = '/';
}
});
return () => {
subscription.unsubscribe();
};
}, [supabase]);
return null;
}