From 59aa7845bad69a1768bb88f83cfcea607c447538 Mon Sep 17 00:00:00 2001 From: josephsellers <6892567+josephsellers@users.noreply.github.com> Date: Sun, 22 Feb 2026 16:01:25 +0000 Subject: [PATCH] fix: correct cookie domain for .local TLD hostnames getCookieDomain() returns '.localhost' for hostnames ending in '.local' (e.g., app.plunk.local), causing the browser to reject the cookie because the domain doesn't match the request origin. Split the .localhost and .local cases so that .local hostnames return the actual base domain (e.g., .plunk.local). --- apps/api/src/services/UserService.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/UserService.ts b/apps/api/src/services/UserService.ts index 1ceea64..1300839 100644 --- a/apps/api/src/services/UserService.ts +++ b/apps/api/src/services/UserService.ts @@ -10,6 +10,7 @@ import {Keys} from './keys.js'; * Extract base domain from URL for cookie sharing across subdomains * e.g., "http://api.example.com" -> ".example.com" * e.g., "http://api.localhost" -> ".localhost" + * e.g., "http://app.plunk.local" -> ".plunk.local" */ function getCookieDomain(): string | undefined { if (NODE_ENV === 'development') { @@ -28,10 +29,14 @@ function getCookieDomain(): string | undefined { // Extract base domain (last two parts for most domains, or .localhost) const parts = hostname.split('.'); if (parts.length >= 2) { - // For *.localhost or *.local, use the full hostname with leading dot - if (hostname.endsWith('.localhost') || hostname.endsWith('.local')) { + // For *.localhost, use .localhost (reserved TLD) + if (hostname.endsWith('.localhost')) { return '.localhost'; } + // For *.local (mDNS TLD), use the actual base domain + if (hostname.endsWith('.local')) { + return `.${parts.slice(-2).join('.')}`; + } // For other domains, use the last two parts (e.g., .example.com) return `.${parts.slice(-2).join('.')}`; }