test: cookie test
All checks were successful
Update changelog / changelog (push) Successful in 27s

This commit is contained in:
Pc
2026-01-06 14:54:04 +01:00
parent 5dd751600c
commit ad76294d73
4 changed files with 24 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ export const Generator: React.FC<GeneratorProps> = ({ url, setUrl, onGenerate })
KittyURL <PawPrint className="w-8 h-8 sm:w-12 sm:h-12" fill="currentColor" /> KittyURL <PawPrint className="w-8 h-8 sm:w-12 sm:h-12" fill="currentColor" />
</h1> </h1>
<p className="text-pink-300 text-lg sm:text-xl font-medium px-4"> <p className="text-pink-300 text-lg sm:text-xl font-medium px-4">
Shorten your links with a purr! Shorten KKKKKK your links with a purr!
</p> </p>
</header> </header>

View File

@@ -7,11 +7,25 @@ const TOKEN_KEY = 'ktty_shared_token';
const getCookieConfig = () => { const getCookieConfig = () => {
const hostname = window.location.hostname; const hostname = window.location.hostname;
// Sprawdzamy, czy jesteśmy na localhost
const isLocal = hostname === 'localhost' || hostname === '127.0.0.1'; const isLocal = hostname === 'localhost' || hostname === '127.0.0.1';
// Sprawdzamy, czy połączenie jest bezpieczne (HTTPS)
const isSecure = window.location.protocol === 'https:';
return { 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', 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, sameSite: 'Lax' as const,
path: '/', path: '/',
expires: 7 expires: 7
}; };
@@ -56,7 +70,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}, []); }, []);
const logout = useCallback(() => { 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); setToken(null);
}, []); }, []);
@@ -65,9 +81,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
isAuthenticated: !!token, isAuthenticated: !!token,
token, token,
loading, loading,
error, // TERAZ OBECNE error,
signIn: (n, p) => authRequest('signIn', n, p), signIn: (n, p) => authRequest('signIn', n, p),
signUp: (n, p) => authRequest('signUp', n, p), // TERAZ OBECNE signUp: (n, p) => authRequest('signUp', n, p),
logout logout
}}> }}>
{children} {children}

View File

@@ -1,4 +1,4 @@
{ {
"compilerOptions": { "compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022", "target": "ES2022",

View File

@@ -1,7 +1,8 @@
{ {
"files": [], "files": [],
"references": [ "references": [
{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" } { "path": "./tsconfig.node.json" }
] ]
} }