Skip to content

Commit

Permalink
Use Okta to get sign in status for Reader Revenue header.
Browse files Browse the repository at this point in the history
Co-authored-by: George B <[email protected]>
Co-authored-by: Jamie B <[email protected]>
  • Loading branch information
3 people committed Jul 18, 2023
1 parent 08466a3 commit e865edf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { dateDiffDays } from '../../../../lib/time-utils';
import { getLocalDate } from '../../../../types/dates';
import type { LocalDate } from '../../../../types/dates';
import type { UserFeaturesResponse } from '../../../../types/membership';
import { isUserLoggedIn } from '../identity/api';
import { isUserLoggedIn, isUserLoggedInOktaRefactor } from '../identity/api';
import { cookieIsExpiredOrMissing, timeInDaysFromNow } from './lib/cookie';

// Persistence keys
Expand Down Expand Up @@ -298,12 +298,18 @@ const isPostAskPauseOneOffContributor = (askPauseDays = 90): boolean => {
return daysSinceLastContribution > askPauseDays;
};

// TODO: Remove as part of Okta migration
const isRecurringContributor = (): boolean =>
// If the user is logged in, but has no cookie yet, play it safe and assume they're a contributor
(isUserLoggedIn() &&
getCookie({ name: RECURRING_CONTRIBUTOR_COOKIE }) !== 'false') ||
supportSiteRecurringCookiePresent();

const isRecurringContributorOkta = async (): Promise<boolean> =>
((await isUserLoggedInOktaRefactor()) &&
getCookie({ name: RECURRING_CONTRIBUTOR_COOKIE }) !== 'false') ||
supportSiteRecurringCookiePresent();

const isDigitalSubscriber = (): boolean =>
getCookie({ name: DIGITAL_SUBSCRIBER_COOKIE }) === 'true';

Expand All @@ -318,11 +324,17 @@ const shouldNotBeShownSupportMessaging = (): boolean =>
which this function is dependent on.
*/

// TODO: Remove as part of Okta migration
const shouldHideSupportMessaging = (): boolean =>
shouldNotBeShownSupportMessaging() ||
isRecentOneOffContributor() || // because members-data-api is unaware of one-off contributions so relies on cookie
isRecurringContributor(); // guest checkout means that members-data-api isn't aware of all recurring contributions so relies on cookie

const shouldHideSupportMessagingOkta = async (): Promise<boolean> =>
shouldNotBeShownSupportMessaging() ||
isRecentOneOffContributor() || // because members-data-api is unaware of one-off contributions so relies on cookie
(await isRecurringContributorOkta()); // guest checkout means that members-data-api isn't aware of all recurring contributions so relies on cookie

const readerRevenueRelevantCookies = [
PAYING_MEMBER_COOKIE,
DIGITAL_SUBSCRIBER_COOKIE,
Expand Down Expand Up @@ -396,6 +408,7 @@ export {
isRecurringContributor,
isDigitalSubscriber,
shouldHideSupportMessaging,
shouldHideSupportMessagingOkta,
refresh,
deleteOldData,
getLastOneOffContributionTimestamp,
Expand Down
12 changes: 6 additions & 6 deletions static/src/javascripts/projects/common/modules/support/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { submitComponentEvent } from 'common/modules/commercial/acquisitions-oph
import {
getLastOneOffContributionDate,
getPurchaseInfo,
shouldHideSupportMessaging,
shouldHideSupportMessagingOkta,
} from 'common/modules/commercial/user-features';
import { isUserLoggedIn } from 'common/modules/identity/api';
import { isUserLoggedInOktaRefactor } from 'common/modules/identity/api';
import {
dynamicImport,
ModulesVersion,
Expand All @@ -20,25 +20,25 @@ import config from 'lib/config';
import { getCountryCode } from 'lib/geolocation';
import { reportError } from 'lib/report-error';

const buildHeaderLinksPayload = (): HeaderPayload => {
const buildHeaderLinksPayload = async (): Promise<HeaderPayload> => {
const countryCode = getCountryCode();
return {
tracking,
targeting: {
showSupportMessaging: !shouldHideSupportMessaging(),
showSupportMessaging: !(await shouldHideSupportMessagingOkta()),
countryCode,
modulesVersion: ModulesVersion,
mvtId: getMvtValue() ?? 0,
lastOneOffContributionDate:
getLastOneOffContributionDate() ?? undefined,
purchaseInfo: getPurchaseInfo(),
isSignedIn: isUserLoggedIn(),
isSignedIn: await isUserLoggedInOktaRefactor(),
},
};
};

export const fetchAndRenderHeaderLinks = async (): Promise<void> => {
const requestData = buildHeaderLinksPayload();
const requestData = await buildHeaderLinksPayload();
const isEnabled = config.get<boolean>('switches.remoteHeader', false);
const { contentType } = window.guardian.config.page;

Expand Down

0 comments on commit e865edf

Please sign in to comment.