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:
@@ -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<HTMLDivElement>(null)
|
||||
const pathname = useRouterState({
|
||||
@@ -145,6 +148,8 @@ const BetterAuthHeader = () => {
|
||||
className={styles.menuButton}
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
clearGuestOrderRefs()
|
||||
clearBasket()
|
||||
void authClient.signOut()
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user