Authentication with Express backend + Next.js frontend
This is my first time using Better Auth, so forgive me if this is obvious
I have an existing backend built with Express, which has Better Auth setup and running.
We are creating a new Next.js frontend, on a separate server, which needs to authenticate against this backend.
After reading the docs, seems like authenticating on the Next.js client side is fairly simple using the
What is the solution if I need to make a server side fetch to our Express backend?
I have an existing backend built with Express, which has Better Auth setup and running.
We are creating a new Next.js frontend, on a separate server, which needs to authenticate against this backend.
After reading the docs, seems like authenticating on the Next.js client side is fairly simple using the
better-auth/react package, but trying to get the session on the Next.js server side requires importing the auth instance, which I cannot access since its on our Express backend. What is the solution if I need to make a server side fetch to our Express backend?
Solution
Well, I followed this for server-side session:
https://www.better-auth.com/docs/integrations/next#for-nextjs-release-1517-and-below
https://www.better-auth.com/docs/integrations/next#for-nextjs-release-1517-and-below
