Invalidate the router on sign out so account orders clear immediately
Signing out only clears the auth session cookie; a route already loaded (e.g. /orders) keeps its stale loader data until something triggers a reload. Call router.invalidate() once signOut succeeds so the current route's loader reruns against the now-signed-out session. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Link, useRouterState } from '@tanstack/react-router'
|
||||
import { Link, useRouter, useRouterState } from '@tanstack/react-router'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { authClient } from '#/lib/auth-client'
|
||||
@@ -66,6 +66,7 @@ const LogOutIcon = () => (
|
||||
const BetterAuthHeader = () => {
|
||||
const { data: session, isPending } = authClient.useSession()
|
||||
const { clear: clearBasket } = useBasket()
|
||||
const router = useRouter()
|
||||
const [open, setOpen] = useState(false)
|
||||
const wrapperRef = useRef<HTMLDivElement>(null)
|
||||
const pathname = useRouterState({
|
||||
@@ -150,7 +151,11 @@ const BetterAuthHeader = () => {
|
||||
setOpen(false)
|
||||
clearGuestOrderRefs()
|
||||
clearBasket()
|
||||
void authClient.signOut()
|
||||
void authClient.signOut({
|
||||
fetchOptions: {
|
||||
onSuccess: () => void router.invalidate(),
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<LogOutIcon />
|
||||
|
||||
Reference in New Issue
Block a user