From cf4aff473c256991f3c9e48846e75516ccd775a8 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Wed, 18 Jun 2025 09:14:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20Update=20COOKIE=5FOPTIONS=20to?= =?UTF-8?q?=20handle=20secure=20cookies=20based=20on=20environment=20(loca?= =?UTF-8?q?lhost=20vs=20production).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/services/cookies/cookies.service.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/services/cookies/cookies.service.ts b/src/app/services/cookies/cookies.service.ts index 8136f7f..64f3a88 100644 --- a/src/app/services/cookies/cookies.service.ts +++ b/src/app/services/cookies/cookies.service.ts @@ -11,12 +11,19 @@ export class CookiesService { private readonly USERNAME_KEY = 'username'; private readonly USER_ID = 'userId'; private readonly IS_ADMIN_KEY = 'isAdmin'; - private readonly COOKIE_OPTIONS = { - path: '/', - domain: window.location.hostname, - secure: true, - sameSite: 'Strict' as const, - }; + + private get COOKIE_OPTIONS() { + const isLocalhost = window.location.hostname === 'localhost' || + window.location.hostname === '127.0.0.1' || + window.location.hostname.includes('localhost'); + + return { + path: '/', + domain: window.location.hostname, + secure: !isLocalhost, + sameSite: 'Strict' as const, + }; + } constructor( private router: Router,