Session is null in Nextjs 15 middleware (Express backend) only in prod
Hi guys, I am able to get session in middleware with nodejs runtime in my dev server, but when I deploy in production it doesn't seem to pass any cookies when I make the request to the expressjs auth server.. What is the issue? Here's my
middleware.ts
6 Replies
don't use authclient in server routes, especially the middleware
dont fetch you database in the middleware
use the cookie helper for the middleware provided by betterauth
I tried using getSessionCookie() or getCookieCache() in the middleware, but they always return null.
have you set different cookie names, e.g. have you customised the cookie in any way? are you following exactly what the docs say?
Next.js integration | Better Auth
Integrate Better Auth with Next.js.
also, if you only have null session in production, then it could be a cors issue if you have a separate backend server
Yes I'm experiencing the same. It is null on production. What cors policy should I add in the request?