Skip to content

Commit e3f61b4

Browse files
committed
fix(payments): clear previous access token on signin
Because: - Payments server reads potentially stale access token from previous session instead of using new access token from current session. This commit: - Clears access token from localStorage when signing in from payments server checkout page. Closes #FXA-11638
1 parent d39aff7 commit e3f61b4

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/fxa-payments-server/src/components/NewUserEmailForm/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useCallbackOnce } from '../../lib/hooks';
1515
import { apiFetchAccountStatus } from '../../lib/apiClient';
1616
import { CheckoutType } from 'fxa-shared/subscriptions/types';
1717
import { metadataFromPlan } from 'fxa-shared/subscriptions/metadata';
18+
import { ACCESS_TOKEN_KEY } from '../..';
1819

1920
const CHECKOUT_TYPE = CheckoutType.WITHOUT_ACCOUNT;
2021
const DEFAULT_NEWSLETTER_STRING_ID =
@@ -116,6 +117,8 @@ export const NewUserEmailForm = ({
116117
}, [onFormEngaged]);
117118

118119
const onClickSignInButton = () => {
120+
// Clear any remaining access token from a previous session
121+
localStorage.removeItem(ACCESS_TOKEN_KEY)
119122
selectedPlan.other = 'click-signnin';
120123
Amplitude.createAccountSignIn({
121124
...selectedPlan,
@@ -289,7 +292,7 @@ export async function emailInputValidationAndAccountCheck(
289292

290293
const errorMsg = getString
291294
? /* istanbul ignore next - not testing l10n here */
292-
getString('new-user-email-validate')
295+
getString('new-user-email-validate')
293296
: 'Email is not valid';
294297

295298
const accountExistsMsg = (
@@ -355,7 +358,7 @@ export function emailConfirmationValidation(
355358

356359
const errorMsg = getString
357360
? /* istanbul ignore next - not testing l10n here */
358-
getString('new-user-email-validate-confirm')
361+
getString('new-user-email-validate-confirm')
359362
: 'Emails do not match';
360363

361364
return {

packages/fxa-payments-server/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { actions } from './store/actions';
1717
import './styles/tailwind.out.css';
1818
import './index.scss';
1919

20+
export const ACCESS_TOKEN_KEY = 'fxa-access-token';
21+
2022
async function init() {
2123
readConfigFromMeta(headQuerySelector);
2224

@@ -109,7 +111,6 @@ async function getHashParams() {
109111
return hashParams;
110112
}
111113

112-
const ACCESS_TOKEN_KEY = 'fxa-access-token';
113114
type getVerifiedAccessTokenArgs = { accessToken?: string | null };
114115
async function getVerifiedAccessToken({
115116
accessToken = '',

0 commit comments

Comments
 (0)