Remove cookies when retiring user

This commit is contained in:
jaebradley
2018-05-16 10:19:33 -04:00
parent 48bff77b45
commit 4045eee57d
2 changed files with 32 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import { Button, Modal, Icon, InputText, StatusAlert } from '@edx/paragon/static
import StringUtils from 'edx-ui-toolkit/js/utils/string-utils';
import { deactivate } from '../AccountsClient';
import removeLoggedInCookies from './removeLoggedInCookies';
class StudentAccountDeletionConfirmationModal extends React.Component {
constructor(props) {
@@ -29,6 +30,7 @@ class StudentAccountDeletionConfirmationModal extends React.Component {
handleConfirmationModalClose() {
this.props.onClose();
removeLoggedInCookies();
window.location.href = 'https://www.edx.org';
}

View File

@@ -0,0 +1,30 @@
import cookie from 'js-cookie';
const removeLoggedInCookies = () => {
const hostname = window.location.hostname;
const isLocalhost = hostname.indexOf('localhost') >= 0;
const isStage = hostname.indexOf('stage') >= 0;
let domain = '.edx.org';
if (isLocalhost) {
domain = 'localhost';
} else if (isStage) {
domain = '.stage.edx.org';
}
cookie.remove('edxloggedin', { domain });
if (isLocalhost) {
// localhost doesn't have prefixes
cookie.remove('csrftoken', { domain });
cookie.remove('edx-user-info', { domain });
} else {
// does not take sandboxes into account
const prefix = isStage ? 'stage' : 'prod';
// both stage and prod csrf tokens are set to .edx.org
cookie.remove(`${prefix}-edx-csrftoken`, { domain: '.edx.org' });
cookie.remove(`${prefix}-edx-user-info`, { domain });
}
};
export default removeLoggedInCookies;