Skip to content

Commit

Permalink
Merge pull request #26432 from guardian/okta/isUserLoggedInOktaRefact…
Browse files Browse the repository at this point in the history
…or-reader-revenue-dev-utils

Use `isUserLoggedInOktaRefactor` in `reader-revenue-dev-utils`
  • Loading branch information
AshCorr authored Aug 8, 2023
2 parents 2e57c27 + ce3422d commit a084f84
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
initMvtCookie,
} from '../analytics/mvt-cookie';
import { clearParticipations } from '../experiments/ab-local-storage';
import { isUserLoggedIn } from '../identity/api';
import { isUserLoggedInOktaRefactor } from '../identity/api';
import userPrefs from '../user-prefs';
import { pageShouldHideReaderRevenue } from './contributions-utilities';
import {
Expand Down Expand Up @@ -53,21 +53,24 @@ const clearCommonReaderRevenueStateAndReload = (asExistingSupporter) => {
fakeOneOffContributor();
}

if (isUserLoggedIn() && !asExistingSupporter) {
if (window.location.origin.includes('localhost')) {
// Assume they don't have identity running locally
// So try and remove the identity cookie manually
removeCookie('GU_U');
} else {
const profileUrl = window.location.origin.replace(
/(www\.|m\.)/,
'profile.',
);
window.location.assign(`${profileUrl}/signout`);
}
} else {
window.location.reload();
}

isUserLoggedInOktaRefactor().then(isLoggedIn => {
if(isLoggedIn && !asExistingSupporter) {
if (window.location.origin.includes('localhost')) {
localStorage.removeItem("gu.access_token");
localStorage.removeItem("gu.id_token");
removeCookie('GU_U');
} else {
const profileUrl = window.location.origin.replace(
/(www\.|m\.)/,
'profile.',
);
window.location.assign(`${profileUrl}/signout`);
}
} else {
window.location.reload();
}
})
};

const showMeTheEpic = (asExistingSupporter = false) => {
Expand Down

0 comments on commit a084f84

Please sign in to comment.