mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 12:11:17 -05:00
feat: Add force logout endpoint
This commit is contained in:
@@ -43,6 +43,7 @@ import AdminSettings from "./pages/AdminSettings";
|
||||
import BlogIndex from "./pages/BlogIndex";
|
||||
import BlogPost from "./pages/BlogPost";
|
||||
import AdminBlog from "./pages/AdminBlog";
|
||||
import ForceLogout from "./pages/ForceLogout";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
@@ -96,6 +97,7 @@ function AppContent() {
|
||||
<Route path="/terms" element={<Terms />} />
|
||||
<Route path="/privacy" element={<Privacy />} />
|
||||
<Route path="/submission-guidelines" element={<SubmissionGuidelines />} />
|
||||
<Route path="/force-logout" element={<ForceLogout />} />
|
||||
{/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
|
||||
@@ -156,6 +156,37 @@ class AuthStorage {
|
||||
: null
|
||||
};
|
||||
}
|
||||
|
||||
// Clear all auth-related storage (for force logout)
|
||||
clearAll(): void {
|
||||
console.log('[AuthStorage] Clearing all auth storage');
|
||||
try {
|
||||
if (this.storage) {
|
||||
// Get all keys from storage
|
||||
const keys: string[] = [];
|
||||
for (let i = 0; i < this.storage.length; i++) {
|
||||
const key = this.storage.key(i);
|
||||
if (key?.startsWith('sb-')) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all Supabase auth keys
|
||||
keys.forEach(key => {
|
||||
console.log('[AuthStorage] Removing key:', key);
|
||||
this.storage!.removeItem(key);
|
||||
});
|
||||
}
|
||||
|
||||
// Clear memory storage
|
||||
this.memoryStorage.clear();
|
||||
console.log('[AuthStorage] ✓ All auth storage cleared');
|
||||
} catch (error) {
|
||||
console.error('[AuthStorage] Error clearing storage:', error);
|
||||
// Still clear memory storage as fallback
|
||||
this.memoryStorage.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const authStorage = new AuthStorage();
|
||||
|
||||
55
src/pages/ForceLogout.tsx
Normal file
55
src/pages/ForceLogout.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import { useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { authStorage } from "@/lib/authStorage";
|
||||
|
||||
/**
|
||||
* ForceLogout - Hidden endpoint for completely clearing auth session
|
||||
* Access via: /force-logout
|
||||
* Not linked anywhere in the UI - for manual navigation only
|
||||
*/
|
||||
const ForceLogout = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const performFullLogout = async () => {
|
||||
console.log('[ForceLogout] Starting complete auth cleanup...');
|
||||
|
||||
try {
|
||||
// 1. Sign out from Supabase
|
||||
console.log('[ForceLogout] Signing out from Supabase...');
|
||||
await supabase.auth.signOut();
|
||||
|
||||
// 2. Clear all auth-related storage
|
||||
console.log('[ForceLogout] Clearing all auth storage...');
|
||||
authStorage.clearAll();
|
||||
|
||||
// 3. Brief delay to ensure cleanup completes
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
console.log('[ForceLogout] ✓ Auth cleanup complete, redirecting to home...');
|
||||
|
||||
// 4. Redirect to home page
|
||||
navigate('/', { replace: true });
|
||||
} catch (error) {
|
||||
console.error('[ForceLogout] Error during logout:', error);
|
||||
// Still redirect even if there's an error
|
||||
navigate('/', { replace: true });
|
||||
}
|
||||
};
|
||||
|
||||
performFullLogout();
|
||||
}, [navigate]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||
<div className="text-center space-y-4">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary mx-auto"></div>
|
||||
<p className="text-lg text-muted-foreground">Clearing session...</p>
|
||||
<p className="text-sm text-muted-foreground">You will be redirected shortly.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ForceLogout;
|
||||
Reference in New Issue
Block a user