Skip to content

Commit 9a0cc25

Browse files
authored
fix(logout): clear Inertia prefetch cache on logout to prevent data leakage. (#97)
Ensure the `router.flushAll()` method is called during the logout process to clear the Inertia prefetch cache. This prevents potential data leakage where a later user on the same device could access preloaded data from the previous session.
1 parent 7e160e0 commit 9a0cc25

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

resources/js/components/user-menu-content.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSep
22
import { UserInfo } from '@/components/user-info';
33
import { useMobileNavigation } from '@/hooks/use-mobile-navigation';
44
import { type User } from '@/types';
5-
import { Link } from '@inertiajs/react';
5+
import { Link, router } from '@inertiajs/react';
66
import { LogOut, Settings } from 'lucide-react';
77

88
interface UserMenuContentProps {
@@ -12,6 +12,11 @@ interface UserMenuContentProps {
1212
export function UserMenuContent({ user }: UserMenuContentProps) {
1313
const cleanup = useMobileNavigation();
1414

15+
const handleLogout = () => {
16+
cleanup();
17+
router.flushAll();
18+
};
19+
1520
return (
1621
<>
1722
<DropdownMenuLabel className="p-0 font-normal">
@@ -30,7 +35,7 @@ export function UserMenuContent({ user }: UserMenuContentProps) {
3035
</DropdownMenuGroup>
3136
<DropdownMenuSeparator />
3237
<DropdownMenuItem asChild>
33-
<Link className="block w-full" method="post" href={route('logout')} as="button" onClick={cleanup}>
38+
<Link className="block w-full" method="post" href={route('logout')} as="button" onClick={handleLogout}>
3439
<LogOut className="mr-2" />
3540
Log out
3641
</Link>

0 commit comments

Comments
 (0)