Skip to content

Commit 12e04e0

Browse files
committed
feat(container): revamp cookie deletion
ref: #MANAGER-21211 Signed-off-by: Dustin Kroger <dustin.kroger.ext@ovhcloud.com>
1 parent 7ee6493 commit 12e04e0

4 files changed

Lines changed: 29 additions & 22 deletions

File tree

packages/manager/apps/container/src/App.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { setupDevApplication } from '@/core/dev';
2121
import { ApplicationProvider } from '@/context';
2222
import Container from '@/container';
2323
import { ApiError } from './types/error.type';
24+
import { deleteMatchingCookies } from './helpers';
2425

2526
function reloadPage() {
2627
window.location.reload();
@@ -55,26 +56,6 @@ function setupI18n(locale: string) {
5556
});
5657
}
5758

58-
const deleteMatchingCookies = () => {
59-
const cookies = document.cookie.split(';');
60-
cookies.forEach((cookie) => {
61-
const cookieName = cookie.split('=')[0].trim();
62-
if (cookieName.startsWith('_biz_') || cookieName.startsWith('_mkto_trk') || cookieName.startsWith('_gcl_au')) {
63-
// Delete the cookie by setting its expiration date to the past
64-
document.cookie = `${cookieName}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
65-
// Also try to delete with domain variations
66-
const domain = window.location.hostname;
67-
document.cookie = `${cookieName}=; path=/; domain=${domain}; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
68-
// Try with parent domain
69-
const domainParts = domain.split('.');
70-
if (domainParts.length > 2) {
71-
const parentDomain = domainParts.slice(-2).join('.');
72-
document.cookie = `${cookieName}=; path=/; domain=.${parentDomain}; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
73-
}
74-
}
75-
});
76-
}
77-
7859
const App = () => {
7960
const [error, setError] = useState(null);
8061
const [environment, setEnvironment] = useState<Environment>(null);

packages/manager/apps/container/src/cookie-policy/CookiePolicy.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useApplication } from '@/context';
2222
import links from './links';
2323
import ovhCloudLogo from '../assets/images/logo-ovhcloud.png';
2424
import { WEBSITE_PRIVACY_COOKIE_NAME, WEBSITE_TRACKING_CONSENT_VALUE } from './CookiePolicy.constants';
25+
import { deleteCookie } from '@/helpers';
2526

2627
type Props = {
2728
shell: Shell;
@@ -85,6 +86,7 @@ const CookiePolicy = ({ shell, onValidate }: Props): JSX.Element => {
8586
setShow(true);
8687
} else {
8788
trackingPlugin.setEnabled(false);
89+
deleteCookie('clientSideUserId');
8890
}
8991
onValidate(isRegionUS || hasConsent);
9092
}, [show]);
@@ -94,10 +96,10 @@ const CookiePolicy = ({ shell, onValidate }: Props): JSX.Element => {
9496
{show && (
9597
<OsdsModal dismissible={false} onClick={(e) => e.stopPropagation()}>
9698
<div className="p-1">
97-
<div className="w-full flex justify-center items-center">
99+
<div className="flex w-full items-center justify-center">
98100
<img src={ovhCloudLogo} alt="ovh-cloud-logo" />
99101
</div>
100-
<div className="text-center m-4">
102+
<div className="m-4 text-center">
101103
<Subtitle>{t('cookie_policy_title')}</Subtitle>
102104
</div>
103105
<div className="mb-3">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const deleteCookie = (cookieName: string) => {
2+
// Delete the cookie by setting its expiration date to the past
3+
document.cookie = `${cookieName}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
4+
// Also try to delete with domain variations
5+
const domain = window.location.hostname;
6+
document.cookie = `${cookieName}=; path=/; domain=${domain}; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
7+
// Try with parent domain
8+
const domainParts = domain.split('.');
9+
if (domainParts.length > 2) {
10+
const parentDomain = domainParts.slice(-2).join('.');
11+
document.cookie = `${cookieName}=; path=/; domain=.${parentDomain}; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
12+
}
13+
};
14+
15+
export const deleteMatchingCookies = () => {
16+
const cookies = document.cookie.split(';');
17+
cookies.forEach((cookie) => {
18+
const cookieName = cookie.split('=')[0].trim();
19+
if (cookieName.startsWith('_biz_') || cookieName.startsWith('_mkto_trk') || cookieName.startsWith('_gcl_au')) {
20+
deleteCookie(cookieName);
21+
}
22+
});
23+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { truncate, capitalize, toScreamingSnakeCase } from './stringHelper/stringHelper';
22
export { groupBy } from './arrayHelper/arrayHelper';
33
export { fromNow } from './dateHelper';
4+
export { deleteMatchingCookies, deleteCookie } from './cookieHelper';

0 commit comments

Comments
 (0)