feat: add global auth listener with hard reload on logout
This commit is contained in:
@@ -8,6 +8,7 @@ import { I18nProvider } from "@/i18n/I18nContext";
|
||||
import { SessionProvider } from "@/context/SessionContext";
|
||||
import ActiveSessionBanner from "@/components/ActiveSessionBanner";
|
||||
import MainContentWrapper from "@/components/MainContentWrapper";
|
||||
import AuthListener from "@/components/AuthListener";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
@@ -46,6 +47,7 @@ export default function RootLayout({
|
||||
<body className={inter.className}>
|
||||
<I18nProvider>
|
||||
<SessionProvider>
|
||||
<AuthListener />
|
||||
<ActiveSessionBanner />
|
||||
<MainContentWrapper>
|
||||
<PWARegistration />
|
||||
|
||||
28
src/components/AuthListener.tsx
Normal file
28
src/components/AuthListener.tsx
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user