local storage buster

This commit is contained in:
Nate Kelley 2025-04-17 11:18:53 -06:00
parent 53e45587f4
commit 0917ae1120
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,17 @@
'use client';
import { useCallback } from 'react';
import { signOut } from '@/lib/supabase/signOut';
import { clearAllBrowserStorage } from '@/lib/browser/storage';
export const useSignOut = () => {
const handleSignOut = useCallback(async () => {
// First clear all client-side storage
clearAllBrowserStorage();
// Then perform server-side sign out
await signOut();
}, []);
return handleSignOut;
};

View File

@ -15,8 +15,8 @@ import { BUSTER_DOCS_URL } from '@/routes/externalRoutes';
import { type DropdownProps, Dropdown } from '@/components/ui/dropdown/Dropdown';
import { AvatarUserButton } from '@/components/ui/avatar/AvatarUserButton';
import { useUserConfigContextSelector } from '@/context/Users';
import { signOut as signOutServer } from '@/lib/supabase/signOut';
import { useContactSupportModalStore } from '@/context/BusterAppLayout';
import { useSignOut } from '@/components/features/auth/SignOutHandler';
export const SidebarUserFooter: React.FC<{}> = () => {
const user = useUserConfigContextSelector((x) => x.user);
@ -26,8 +26,10 @@ export const SidebarUserFooter: React.FC<{}> = () => {
if (!name || !email) return null;
const handleSignOut = useSignOut();
return (
<SidebarUserDropdown signOut={signOutServer}>
<SidebarUserDropdown signOut={handleSignOut}>
<div className="flex w-full">
<AvatarUserButton username={name} email={email} />
</div>

View File

@ -0,0 +1,17 @@
/**
* Clears all browser storage including localStorage, sessionStorage, and cookies
* @returns void
*/
export const clearAllBrowserStorage = (): void => {
// Clear localStorage
localStorage.clear();
// Clear sessionStorage
sessionStorage.clear();
// Clear all cookies
document.cookie.split(';').forEach((cookie) => {
const cookieName = cookie.replace(/^ +/, '').split('=')[0];
document.cookie = `${cookieName}=;expires=${new Date().toUTCString()};path=/`;
});
};

View File

@ -3,10 +3,18 @@
import { createClient } from './server';
import { redirect } from 'next/navigation';
import { BusterRoutes, createBusterRoute } from '@/routes/busterRoutes';
import { cookies } from 'next/headers';
export const signOut = async () => {
'use server';
const supabase = await createClient();
const cookieStore = cookies();
// Clear all cookies
const allCookies = cookieStore.getAll();
allCookies.forEach((cookie) => {
cookieStore.delete(cookie.name);
});
const { error } = await supabase.auth.signOut();