Add query parameter support to useSession().refetch() for cache control consistency #1671

Closed
opened 2026-03-13 08:55:00 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @adriandlam on GitHub (Aug 8, 2025).

Is this suited for github?

  • Yes, this is suited for github

Currently, getSession() supports query parameters like { disableCookieCache: true }, but useSession().refetch() doesn't. This creates an inconsistent API where I have to import and use both methods just to bypass cookie cache after updating user data. When using optimistic updates with cookie caching enabled, the session remains stale even after calling refetch(), requiring a workaround with getSession({ query: { disableCookieCache: true }}).

Describe the solution you'd like

I'd like useSession().refetch() to accept the same query parameters as getSession():

const { refetch } = useSession();
await refetch({ query: { disableCookieCache: true }});

This would provide API consistency and eliminate the need to import both useSession() and getSession() for cache invalidation.

Describe alternatives you've considered

Current workaround:

import { useSession, getSession } from '@/lib/auth-client';

const { data: session, refetch } = useSession();
// After mutation...
const newSession = await getSession({ query: { disableCookieCache: true }});

Other alternatives considered:

  • Disabling cookie cache entirely (loses performance benefits)
  • Using shorter cache duration (still has timing issues)
  • Manual state management (defeats the purpose of the session hook)
Originally created by @adriandlam on GitHub (Aug 8, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, `getSession()` supports query parameters like `{ disableCookieCache: true }`, but `useSession().refetch()` doesn't. This creates an inconsistent API where I have to import and use both methods just to bypass cookie cache after updating user data. When using optimistic updates with cookie caching enabled, the session remains stale even after calling `refetch()`, requiring a workaround with `getSession({ query: { disableCookieCache: true }})`. ### Describe the solution you'd like I'd like `useSession().refetch()` to accept the same query parameters as `getSession()`: ```ts const { refetch } = useSession(); await refetch({ query: { disableCookieCache: true }}); ``` This would provide API consistency and eliminate the need to import both `useSession()` and `getSession()` for cache invalidation. ### Describe alternatives you've considered Current workaround: ```ts import { useSession, getSession } from '@/lib/auth-client'; const { data: session, refetch } = useSession(); // After mutation... const newSession = await getSession({ query: { disableCookieCache: true }}); ``` Other alternatives considered: - Disabling cookie cache entirely (loses performance benefits) - Using shorter cache duration (still has timing issues) - Manual state management (defeats the purpose of the session hook)
GiteaMirror added the enhancement label 2026-03-13 08:55:00 -05:00
Author
Owner

@adriandlam commented on GitHub (Aug 8, 2025):

Working on this now, will submit a PR soon

@adriandlam commented on GitHub (Aug 8, 2025): Working on this now, will submit a PR soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1671