Fetch up-to-date session

What is the best way to fetch an up-to-date session on the client? I need to check if the user is still on the waitlist when they get to a certain page, and I'd rather do this with up to date info. I can always just create an api route to do this, but it's in the user object and would be nice to just refetch the user.
Solution:
you can do this ```ts await authClient.getSession({ //pull fresh user info from the database query: {...
Jump to solution
5 Replies
Lukas
LukasOP3w ago
pls ping if you answer btw
Max
Max2w ago
https://www.better-auth.com/docs/concepts/session-management
import { authClient } from "@/lib/client"
const { data: session } = await authClient.getSession()
import { authClient } from "@/lib/client"
const { data: session } = await authClient.getSession()
@Lukas would this work? this is the api i use
Session Management | Better Auth
Better Auth session management.
Lukas
LukasOP2w ago
my understanding is that getSession just pulls it from cache, is this incorrect?
Solution
Max
Max2w ago
you can do this
await authClient.getSession({ //pull fresh user info from the database
query: {
disableCookieCache: true,
},
})
await authClient.getSession({ //pull fresh user info from the database
query: {
disableCookieCache: true,
},
})
Lukas
LukasOP2w ago
thank you!

Did you find this page helpful?