Facing difficulties with NextJS + Hono + D1 (Cloudflare stack)

Hi I am trying to make better-auth work with nextjs + hono in the cloudflare stack. But I'm having some difficulties doing so!
Main goal is:
  • Nextjs should be deployed to Cloudflare pages.
  • Hono should be deployed to Cloudflare workers.
  • Will be using Cloudflare D1 as database.
Problems I'm facing:
  • When I hit /auth/session It doesn't return the session. Actually when I pass c.req.raw.headers in the getSession method, the header doesn't contain the better_session_token cookie. Although I can see the cookie is there in my browser. Idk! Maybe I'm doing something wrong.
  • Am I doing things the right way?
Notes:
  • I had to manually define /login /register etc auth routes to get typesafety in hono client RPC.
I'm just trying to figure out using this stack with better auth. If anyone can help or have any example working repo would be very helpful!

Repo: https://github.com/raikusy/nextjs-hono-better-auth-d1
GitHub
Contribute to raikusy/nextjs-hono-better-auth-d1 development by creating an account on GitHub.
Was this page helpful?