Files
twenty/packages/twenty-front/src/utils/cookie-storage.ts
T
Félix MalfaitandGitHub d4914aa130 Fix workspace logo, cookie security, and improve workspace impersonation (#14838)
3 small fixes:
- Fix workspace logo
- Improve cookie security
- Improve workspace impersonation
2025-10-02 18:36:52 +02:00

37 lines
772 B
TypeScript

import Cookies from 'js-cookie';
class CookieStorage {
private keys: Set<string> = new Set();
getItem(key: string): string | undefined {
return Cookies.get(key);
}
setItem(
key: string,
value: string,
attributes?: Cookies.CookieAttributes,
): void {
this.keys.add(key);
const secureAttributes = {
secure: window.location.protocol === 'https:',
sameSite: 'lax' as const,
...attributes,
};
Cookies.set(key, value, secureAttributes);
}
removeItem(key: string, attributes?: Cookies.CookieAttributes): void {
this.keys.delete(key);
Cookies.remove(key, attributes);
}
clear(): void {
this.keys.forEach((key) => this.removeItem(key));
}
}
export const cookieStorage = new CookieStorage();