From a2e97c293d02a0d683a2bd71d6944320fe9f5d1b Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 13 Sep 2026 19:39:10 +0200 Subject: [PATCH] Clear guest order refs and basket on sign out Guest order refs and the basket both live in localStorage independent of the auth session, so they'd otherwise linger for the next person to use the browser. Add clearGuestOrderRefs (mirroring clearGuestIdentity) and call it alongside the existing basket clear() from the sign-out handler. Co-Authored-By: Claude Sonnet 5 --- src/integrations/better-auth/header-user.tsx | 5 +++++ src/lib/guestOrders.ts | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/integrations/better-auth/header-user.tsx b/src/integrations/better-auth/header-user.tsx index 95aa9bf..6242538 100644 --- a/src/integrations/better-auth/header-user.tsx +++ b/src/integrations/better-auth/header-user.tsx @@ -2,6 +2,8 @@ import { Link, useRouterState } from '@tanstack/react-router' import { useEffect, useRef, useState } from 'react' import { authClient } from '#/lib/auth-client' +import { useBasket } from '#/lib/basket' +import { clearGuestOrderRefs } from '#/lib/guestOrders' import styles from './header-user.module.scss' @@ -63,6 +65,7 @@ const LogOutIcon = () => ( const BetterAuthHeader = () => { const { data: session, isPending } = authClient.useSession() + const { clear: clearBasket } = useBasket() const [open, setOpen] = useState(false) const wrapperRef = useRef(null) const pathname = useRouterState({ @@ -145,6 +148,8 @@ const BetterAuthHeader = () => { className={styles.menuButton} onClick={() => { setOpen(false) + clearGuestOrderRefs() + clearBasket() void authClient.signOut() }} > diff --git a/src/lib/guestOrders.ts b/src/lib/guestOrders.ts index 99c0f05..f1e4b8f 100644 --- a/src/lib/guestOrders.ts +++ b/src/lib/guestOrders.ts @@ -36,3 +36,11 @@ export const addGuestOrderRef = (ref: GuestOrderRef) => { // own link, it just won't show up in the local Orders list. } } + +export const clearGuestOrderRefs = () => { + try { + window.localStorage.removeItem(STORAGE_KEY) + } catch { + // Unavailable — nothing to clear. + } +}