From ad76294d73abbc56bd9e13ac394af185e52e97e8 Mon Sep 17 00:00:00 2001 From: Pc Date: Tue, 6 Jan 2026 14:54:04 +0100 Subject: [PATCH] test: cookie test --- .../src/components/Generator.tsx | 2 +- .../src/context/AuthProvider.tsx | 24 +++++++++++++++---- kittyurl-frontend/tsconfig.app.json | 2 +- kittyurl-frontend/tsconfig.json | 3 ++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/kittyurl-frontend/src/components/Generator.tsx b/kittyurl-frontend/src/components/Generator.tsx index 771c823..08c2bb4 100644 --- a/kittyurl-frontend/src/components/Generator.tsx +++ b/kittyurl-frontend/src/components/Generator.tsx @@ -15,7 +15,7 @@ export const Generator: React.FC = ({ url, setUrl, onGenerate }) KittyURL

- Shorten your links with a purr! + Shorten KKKKKK your links with a purr!

diff --git a/kittyurl-frontend/src/context/AuthProvider.tsx b/kittyurl-frontend/src/context/AuthProvider.tsx index 739b72c..9a6fc17 100644 --- a/kittyurl-frontend/src/context/AuthProvider.tsx +++ b/kittyurl-frontend/src/context/AuthProvider.tsx @@ -7,11 +7,25 @@ const TOKEN_KEY = 'ktty_shared_token'; const getCookieConfig = () => { const hostname = window.location.hostname; + + // Sprawdzamy, czy jesteśmy na localhost const isLocal = hostname === 'localhost' || hostname === '127.0.0.1'; + + // Sprawdzamy, czy połączenie jest bezpieczne (HTTPS) + const isSecure = window.location.protocol === 'https:'; + return { + // Na produkcji używamy domeny nadrzędnej z kropką, by działało na subdomenach + // Na localhost MUSI być undefined, inaczej przeglądarka odrzuci ciasteczko domain: isLocal ? undefined : '.ktty.is', - secure: !isLocal, + + // Atrybut Secure wymaga HTTPS. Na localhost wyłączamy, na produkcji włączamy. + secure: isSecure, + + // 'Lax' jest bezpieczne i pozwala na współdzielenie w obrębie subdomen. + // Jeśli API jest na zupełnie innej domenie, rozważ 'None' (wymaga Secure: true). sameSite: 'Lax' as const, + path: '/', expires: 7 }; @@ -56,7 +70,9 @@ export function AuthProvider({ children }: { children: ReactNode }) { }, []); const logout = useCallback(() => { - Cookies.remove(TOKEN_KEY, { domain: getCookieConfig().domain, path: '/' }); + const config = getCookieConfig(); + // When removing, you must match the domain and path used when setting + Cookies.remove(TOKEN_KEY, { domain: config.domain, path: config.path }); setToken(null); }, []); @@ -65,9 +81,9 @@ export function AuthProvider({ children }: { children: ReactNode }) { isAuthenticated: !!token, token, loading, - error, // TERAZ OBECNE + error, signIn: (n, p) => authRequest('signIn', n, p), - signUp: (n, p) => authRequest('signUp', n, p), // TERAZ OBECNE + signUp: (n, p) => authRequest('signUp', n, p), logout }}> {children} diff --git a/kittyurl-frontend/tsconfig.app.json b/kittyurl-frontend/tsconfig.app.json index a9b5a59..69a7c94 100644 --- a/kittyurl-frontend/tsconfig.app.json +++ b/kittyurl-frontend/tsconfig.app.json @@ -1,4 +1,4 @@ -{ +{ "compilerOptions": { "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", "target": "ES2022", diff --git a/kittyurl-frontend/tsconfig.json b/kittyurl-frontend/tsconfig.json index 1ffef60..32e54b1 100644 --- a/kittyurl-frontend/tsconfig.json +++ b/kittyurl-frontend/tsconfig.json @@ -1,7 +1,8 @@ -{ +{ "files": [], "references": [ { "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" } + ] }