Skip to content

Commit

Permalink
fix: SEO-219 Enable cookies for subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzarius authored and adamstankiewicz committed Dec 16, 2022
1 parent b7e5440 commit cfa30a1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/CCPADialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Cookies from 'js-cookie';

const CCPA_COOKIE_NAME = 'edx_do_not_sell';

function CCPADialog({ dialogIsOpen, closeCallback, baseURL }) {
const CCPADialog = ({ dialogIsOpen, closeCallback, baseURL }) => {
const [isOpen, open, close] = useToggle(dialogIsOpen);

const getDoNotSellCookie = () => Cookies.get(CCPA_COOKIE_NAME) === 'true';
Expand All @@ -29,9 +29,14 @@ function CCPADialog({ dialogIsOpen, closeCallback, baseURL }) {

const setDoNotSellCookie = (value) => {
const { host } = new URL(baseURL);
// Use global domain (`.edx.org`) without the subdomain
const hostParts = host.split('.');
const domain = hostParts.length > 2
? `.${hostParts.slice(-2).join('.')}`
: host;
const cookieOptions = host.startsWith('localhost')
? {}
: { domain: host, expires: 365 };
: { domain, expires: 365 };
if (!value) {
// If cookie is not set to true, then default to sharing the data
Cookies.remove(CCPA_COOKIE_NAME, cookieOptions);
Expand Down Expand Up @@ -128,7 +133,7 @@ function CCPADialog({ dialogIsOpen, closeCallback, baseURL }) {
</ModalDialog.Footer>
</ModalDialog>
);
}
};

CCPADialog.propTypes = {
dialogIsOpen: PropTypes.bool,
Expand Down

0 comments on commit cfa30a1

Please sign in to comment.