fix(auth): configurable SameSite cookie for cross-origin dev setup

Chrome 89+ schemeful same-site treats http://localhost and https://localhost
as different sites, blocking SameSite=Strict cookies on cross-origin fetch
(e.g. Vite on port 5173, API on port 7221).

Fix: make CookieSameSite configurable per environment in JwtSettings.
- Default: Strict (production)
- appsettings.Development.json: None (allows cross-origin cookie in dev)
- When SameSite=None, Secure is always forced (browser requirement)

Revert the earlier Vite proxy approach in favour of this backend config.
VITE_API_BASE_URL remains a freely configurable URL in .env.local.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 15:42:56 +02:00
co-authored by Claude Haiku 4.5
parent 546b773781
commit 5331be4279
6 changed files with 24 additions and 27 deletions
+5 -10
View File
@@ -1,11 +1,6 @@
# Base URL of the SlpModularCms .NET API.
#
# LOCAL DEV (recommended): leave empty and configure the Vite proxy in
# vite.config.ts. The proxy forwards /api/* to the backend so all requests
# stay same-origin — required for the SameSite=Strict refresh-token cookie.
VITE_API_BASE_URL=
# DIRECT (no proxy): point to the backend URL. CORS must allow this origin
# with credentials, and SameSite may block the cookie on page reload if the
# schemes differ (e.g. http frontend → https backend).
# VITE_API_BASE_URL=https://localhost:7221
# The backend must be running with CORS configured to allow this origin
# and to send the httpOnly refresh-token cookie (credentials: include).
# Set CookieSameSite=None in appsettings.Development.json so the cookie
# is sent cross-origin when the frontend and backend run on different ports.
VITE_API_BASE_URL=https://localhost:7221
+1 -2
View File
@@ -6,8 +6,7 @@ import { z } from 'zod';
* once and only warns in development — production trusts the build-time env.
*/
const configSchema = z.object({
// Empty string = use Vite proxy (same-origin); a full URL = direct mode.
apiBaseUrl: z.union([z.literal(''), z.string().url()]),
apiBaseUrl: z.string().url(),
});
export type AppConfig = z.infer<typeof configSchema>;
-11
View File
@@ -14,17 +14,6 @@ export default defineConfig({
},
server: {
port: 5173,
proxy: {
// Route all /api calls through the Vite dev server so the browser
// sees a single origin. Without this the refreshToken cookie
// (SameSite=Strict) is not sent from http://localhost to
// https://localhost (different scheme = cross-site in Chrome 89+).
'/api': {
target: 'https://localhost:7221',
changeOrigin: true,
secure: false, // allow self-signed dev cert
},
},
},
test: {
globals: true,