Next.js App Router + separate FastAPI: do people actually put the session on Next and mint a Bearer for the API, or am I overcomplicating this?
10:22 14 Aug 2026

We have Next.js (App Router) on app.example.com and FastAPI on api.example.com. FastAPI is not “the Next backend.” It also serves:

  • the website

  • external users with X-API-Key

  • later, a mobile app

Login today is Google Identity Services (button in a Client Component). The browser POSTs the Google ID token to FastAPI. FastAPI verifies it, upserts the user in Mongo, mints our own JWT, and sets an HttpOnly cookie on the API host. Client Components then fetch(api, { credentials: 'include' }). CORS + SameSite=Lax. It works.

Almost every page.js is 'use client'. Auth is useEffect → GET /auth/me. Vercel’s React guidance is basically: don’t useEffect for initial data, fetch in Server Components.

That’s where I get stuck.

A Server Component only sees cookies on the Next.js request. It will never see api.example.com’s HttpOnly cookie. So if we want SCs to call FastAPI as the logged-in user, the session cookie has to live on Next.js (or we put both apps on one host).

What we’re considering (and this feels like a lot):

  1. GIS still runs in the browser (same Google Client ID).

  2. Browser POSTs the ID token to Next.js /api/auth/google.

  3. Next.js server calls FastAPI /auth/google (internal). FastAPI still verifies Google and mints our access + refresh JWTs. It does not Set-Cookie for the website.

  4. Next.js sets access_token + refresh_token as HttpOnly cookies on the Next origin.

  5. Server Components: read the access cookie, fetch(FastAPI, { Authorization: Bearer }).

  6. Client Components (chat SSE, live transcripts — these cannot be RSC): GET /api/auth/token on Next, then call FastAPI directly with Bearer. No BFF proxy. EventSource can’t set Authorization, so those streams become fetch + SSE.

  7. On 401, CC hits Next /api/auth/refresh (refresh cookie → new access cookie). Refresh talks to our API, not Google. GIS never gave us a Google refresh token.

  8. External users: still X-API-Key on FastAPI. Mobile: still POST /auth/google → JSON tokens → Bearer. They never touch Next.

We are explicitly not doing the full BFF (proxy every CC call through Next). Chat/SSE would just add a hop.

Questions for people who actually run this in prod:

  1. Is this the normal “Next as website, Python as resource server” setup, or are we inventing a snowflake?

  2. Do you keep the session on Next (Auth.js / cookies) and send Bearer to the API, or do you give up on Server Components and keep the SPA + API cookie we have now?

  3. /api/auth/token means XSS can steal the access JWT. Do you accept that, use a very short TTL, or swallow the BFF hop?

  4. Same-host reverse proxy (app.example.com/api → FastAPI) so one first-party cookie — is that what teams actually do instead of this?

  5. Honest one: if the UI is already a Client Component SPA, is fighting for RSC data fetching even worth this?

I keep thinking “Next.js can’t possibly need this much auth machinery.” Then I remember Google can only redirect to one origin, cookies are domain-bound, SCs don’t see the other host’s cookies, and FastAPI has to stay usable without a browser. That’s four constraints, not Next being extra.

If you’ve shipped App Router + a separate API (FastAPI, Rails, Go, whatever) with Google login, what did you actually deploy? Auth.js? SPA cookies on the API? ALB path routing? Something else?

authentication next.js cookies oauth-2.0 jwt