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 <noreply@anthropic.com>
This commit is contained in:
2026-09-13 19:39:10 +02:00
co-authored by Claude Sonnet 5
parent 86d1a32dd8
commit a2e97c293d
2 changed files with 13 additions and 0 deletions
@@ -2,6 +2,8 @@ import { Link, useRouterState } from '@tanstack/react-router'
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { authClient } from '#/lib/auth-client' import { authClient } from '#/lib/auth-client'
import { useBasket } from '#/lib/basket'
import { clearGuestOrderRefs } from '#/lib/guestOrders'
import styles from './header-user.module.scss' import styles from './header-user.module.scss'
@@ -63,6 +65,7 @@ const LogOutIcon = () => (
const BetterAuthHeader = () => { const BetterAuthHeader = () => {
const { data: session, isPending } = authClient.useSession() const { data: session, isPending } = authClient.useSession()
const { clear: clearBasket } = useBasket()
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const wrapperRef = useRef<HTMLDivElement>(null) const wrapperRef = useRef<HTMLDivElement>(null)
const pathname = useRouterState({ const pathname = useRouterState({
@@ -145,6 +148,8 @@ const BetterAuthHeader = () => {
className={styles.menuButton} className={styles.menuButton}
onClick={() => { onClick={() => {
setOpen(false) setOpen(false)
clearGuestOrderRefs()
clearBasket()
void authClient.signOut() void authClient.signOut()
}} }}
> >
+8
View File
@@ -36,3 +36,11 @@ export const addGuestOrderRef = (ref: GuestOrderRef) => {
// own link, it just won't show up in the local Orders list. // 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.
}
}