r/nextjs • u/Intelligent-Meet-504 • Aug 25 '26
Discussion Looking for advice: Next.js frontend + separate Node/Express backend — Axios, React Query, SSR & auth?
Hey everyone,
I'm working on an application where I have:
- Frontend: Next.js + TypeScript
- Backend: Node.js + Express + MongoDB
- Authentication: JWT (access token + refresh token)
- Validation: Zod
My frontend and backend are completely separate projects.
I'm trying to figure out a clean, production-friendly architecture for handling authentication, API calls, SSR, CSR, and data fetching in Next.js.
A few things I'm currently considering:
Axios
- Do you use a centralized Axios instance in Next.js?
- Do you use Axios request/response interceptors for attaching access tokens and handling
401 → refresh token → retry request? - If you're using Next.js Server Components, how do you handle Axios differently between server-side and client-side requests?
Authentication
- Where do you store the access token and refresh token?
- Are you using an HttpOnly cookie for the refresh token?
- How do you handle authentication consistently between Server Components and Client Components?
- Do you use
proxy.ts/middleware for protecting routes, or do you handle authentication somewhere else?
React Query / TanStack Query
- I would like to use TanStack Query (React Query) for API data fetching instead of manually using
useEffect+useState. - Is this a good approach with Next.js when the actual API is a separate Express backend?
- How do you handle SSR/prefetching/hydration with TanStack Query and a separate backend?
- Do you use TanStack Query for almost all client-side API data, while using Server Components for initial/server-side data?
- I would like to use TanStack Query (React Query) for API data fetching instead of manually using
- Overall architecture What does your real-world setup look like?
Next.js
↓
Axios / fetch / TanStack Query?
↓
Separate Express API
↓
MongoDBI'm particularly interested in hearing from developers who are actually running this kind of architecture in production.
If you have a separate Node/Express backend and Next.js frontend, what stack and architecture are you using today, and what would you recommend avoiding?
Thanks!
3
u/Few-Ocelot-3271 Aug 25 '26
one thing id push back on, you probably dont need a centralized axios instance on the server side at all. server components can just use fetch directly with the cookies forwarded from the request. save the interceptor pattern for client components where the retry logic actually matters
2
u/Rajat0741 Aug 25 '26 edited Aug 25 '26
If next.js is the only consumer, i think you should drop express and use next.js for backend too, this will also save you from separate domain, untrusted cookies issue in browsers like brave and samsung internet.
Tanstack query + better-auth ( authentication ) +better-fetch ( 0 extra bundle size as it's used by better-auth internally, you need to install it separately as dependency though)
I use these ideally in my personal projects, works pretty well
I use the following template ( it's mine ) for scaffolding next.js projects quickly: https://github.com/Rajat0741/better-next
1
u/canarydev Aug 25 '26
for the express API is it just your next app that consumes it or do you have a mobile component also?
so i run a similar split in production right now where I use nextjs with an express backend, with some go services for newer verticals.
reality is you are not gong to know yet if you will keep express, have a mobile app, or restructure. so just pick defaults that make every one of those changes small.
none of this really decides your architecture up front. just makes the decisions changeable.
1
u/[deleted] Aug 25 '26
[removed] — view removed comment