#Session Persistence Issues: Medusa v2 + Next.js 15 (Auth 200 but session lost)

1 messages · Page 1 of 1 (latest)

heady blaze
#

Hey everyone! ⚓
We are hitting a wall with customer session persistence in Medusa v2 (v2.13.4) using the Next.js 15 Starter (React 19).
The Issue:
Customer login via emailpass returns a 200 OK, but the session is lost immediately on the next page load or route transition. This is especially broken on iOS Safari, leading to constant throwOnHydrationMismatch errors as the UI toggles between Guest and Authenticated states.
Our Setup:
• Backend: Medusa v2.13.4
• Storefront: Next.js 15 (App Router)
• Env: Subdomains (admin.example.com vs www.example.com)
The Weird Part (Config):
In our medusa-config.ts, we’ve tried forcing cookie settings, but the defineConfig type for v2 doesn't seem to recognize them, forcing us to use @ts-ignore:

// medusa-config.ts -> projectConfig.http
// @ts-ignore
cookieDomain: ".example.com",
// @ts-ignore
cookieSameSite: "lax",
// @ts-ignore
cookieSecure: true,

Questions:

  1. What is the "v2 way" to globally configure cookieDomain and SameSite since they aren't in the standard http type anymore?
  2. With Next.js 15, do we need to manually sync the JWT/Cookie in middleware.ts to ensure Server Components see the session?
  3. Any known issues with iOS Safari ITP and Medusa v2's default cookie handling?
    Any "recipes" or pointers to stable multi-subdomain auth would be life-saving! Thanks! 🙏
forest vapor
#

Try removing the '.' before '.example.com'. Also, you could try removing that domain setting altogether. The default should work for your setup.

fresh stone
#

@heady blaze
I use medusa v2.13.4 as well and nextjs starter
i didn't face any of this in production
and i didnt configure cookies at all in medusa.config.ts

my admin site is served at admin.domain.com and storefront at domain.com

#

is this happening in production or development