Better auth does not work on NextJS
Hi guys, im trying to add Better Auth to my empty nextjs project but it does not work. I copied the demo project and it does work there, i copied every auth related file but i still cant get it to work in my project. im trying to check the session on a server component like this but the session is always null. I have not added a database as i dont need one, im logging in using my google account. I keep getting redirected to /sign-in and the console shows this error:
My dashboard page:
14 Replies
Did you enable the nextCookies plugin
@daveycodez Yes, i added it like this but does not seem to help
Are you seeing cookies get set in chrome inspector
2025-04-20T19:46:49.619Z WARN [Better Auth]: No database configuration provided. Using memory adapter in development
is it your full auth config?
if its , its wrong
if not, send all config
not about nextCookies plugin
Yes this is my auth config, i also have a auth-client, middleware and a api route for auth.
auth.ts:
auth-client.ts:
Middleware
api/auth/[...all]/route.ts:
Do i miss anything?
Your middleware looks like an infinite redirect
whenever at "/" and no cookies, redirect to "/"
true, i changed it to be more logical, but the issues still exists
Cookies in Chrome console?
Seems to be okay

For better performance, you can change your middleware to see.
Okay thank you, but does not seem to be the solution to why I don't have a session in my dashboard page (server side)
bro where is your database
of course you cant access to session because there is no database
2025-04-20T19:46:49.619Z WARN [Better Auth]: No database configuration provided. Using memory adapter in development
This warning made me think it is possible to work with the in memory adapter
Don’t do this if you host on Vercel. This will be excessive middleware requests. It’s better to only run it when you need it
The only time you need catch all middleware is for localization routing (next-intl)
If you are only protecting specific routes with optimistic cookie checks, then hardcode them into the middleware check
Next.js docs encourage you to use practices that cause you to pay $$$$ to Vercel unnecessarily across the board
Like excessive dynamic SSR