Better Auth getSessionCookie vs getSession: What’s the Difference?
getSessionCookie looks for Better Auth’s session cookie, and getSession checks the session itself. One route shows the difference in three cases.
- Web Application
- Better Auth
getSessionCookie looks for Better Auth’s session cookie, and getSession checks the session itself. One route shows the difference in three cases.
Protect a Next.js API route with Better Auth: read the session from the request and answer with a 401 error when nobody is signed in.
Turn away signed-out visitors in proxy.ts, before Next.js starts on the page, with Better Auth’s getSessionCookie and a matcher for the paths to protect.
Read the Better Auth session in a Next.js server component and send signed-out visitors to the sign-in page, with a small dashboard page as the example.
npm run build stopped with “Next.js encountered uncached or runtime data during prerendering” after a Next.js 16 page read the Better Auth session at its top. The fix: move that read into a component inside Suspense.
Check the Better Auth session on the server in Next.js 16: a private account page, an early redirect in proxy.ts, a sign-out server action and an API route that answers 401.