mirror of https://github.com/buster-so/buster.git
local storage buster
This commit is contained in:
parent
53e45587f4
commit
0917ae1120
|
@ -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;
|
||||||
|
};
|
|
@ -15,8 +15,8 @@ import { BUSTER_DOCS_URL } from '@/routes/externalRoutes';
|
||||||
import { type DropdownProps, Dropdown } from '@/components/ui/dropdown/Dropdown';
|
import { type DropdownProps, Dropdown } from '@/components/ui/dropdown/Dropdown';
|
||||||
import { AvatarUserButton } from '@/components/ui/avatar/AvatarUserButton';
|
import { AvatarUserButton } from '@/components/ui/avatar/AvatarUserButton';
|
||||||
import { useUserConfigContextSelector } from '@/context/Users';
|
import { useUserConfigContextSelector } from '@/context/Users';
|
||||||
import { signOut as signOutServer } from '@/lib/supabase/signOut';
|
|
||||||
import { useContactSupportModalStore } from '@/context/BusterAppLayout';
|
import { useContactSupportModalStore } from '@/context/BusterAppLayout';
|
||||||
|
import { useSignOut } from '@/components/features/auth/SignOutHandler';
|
||||||
|
|
||||||
export const SidebarUserFooter: React.FC<{}> = () => {
|
export const SidebarUserFooter: React.FC<{}> = () => {
|
||||||
const user = useUserConfigContextSelector((x) => x.user);
|
const user = useUserConfigContextSelector((x) => x.user);
|
||||||
|
@ -26,8 +26,10 @@ export const SidebarUserFooter: React.FC<{}> = () => {
|
||||||
|
|
||||||
if (!name || !email) return null;
|
if (!name || !email) return null;
|
||||||
|
|
||||||
|
const handleSignOut = useSignOut();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarUserDropdown signOut={signOutServer}>
|
<SidebarUserDropdown signOut={handleSignOut}>
|
||||||
<div className="flex w-full">
|
<div className="flex w-full">
|
||||||
<AvatarUserButton username={name} email={email} />
|
<AvatarUserButton username={name} email={email} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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=/`;
|
||||||
|
});
|
||||||
|
};
|
|
@ -3,10 +3,18 @@
|
||||||
import { createClient } from './server';
|
import { createClient } from './server';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { BusterRoutes, createBusterRoute } from '@/routes/busterRoutes';
|
import { BusterRoutes, createBusterRoute } from '@/routes/busterRoutes';
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
export const signOut = async () => {
|
export const signOut = async () => {
|
||||||
'use server';
|
'use server';
|
||||||
const supabase = await createClient();
|
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();
|
const { error } = await supabase.auth.signOut();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue