Skip to content

Commit

Permalink
Social login: Catch inaccessible sessionStorage errors (#88791)
Browse files Browse the repository at this point in the history
* Catch errors when `sessionStorage` isn't available

* Add improved error message with documentation link
  • Loading branch information
ivan-ottinger authored Mar 22, 2024
1 parent 7f3d424 commit 59c6952
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions client/blocks/signup-form/social.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { localizeUrl } from '@automattic/i18n-utils';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
Expand All @@ -7,6 +8,7 @@ import { isWooOAuth2Client } from 'calypso/lib/oauth2-clients';
import { login } from 'calypso/lib/paths';
import { isWpccFlow } from 'calypso/signup/is-flow';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { errorNotice } from 'calypso/state/notices/actions';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
Expand Down Expand Up @@ -108,8 +110,27 @@ class SocialSignupForm extends Component {
trackLoginAndRememberRedirect = ( service ) => {
this.trackSocialSignup( service );

if ( this.props.redirectToAfterLoginUrl && typeof window !== 'undefined' ) {
window.sessionStorage.setItem( 'signup_redirect_to', this.props.redirectToAfterLoginUrl );
try {
if ( this.props.redirectToAfterLoginUrl && typeof window !== 'undefined' ) {
window.sessionStorage.setItem( 'signup_redirect_to', this.props.redirectToAfterLoginUrl );
}
} catch ( error ) {
this.props.showErrorNotice(
this.props.translate(
'Error accessing sessionStorage. {{a}}Please check your browser settings{{/a}}.',
{
components: {
a: (
<a
href={ localizeUrl( 'https://wordpress.com/support/browser-issues/' ) }
target="_blank"
rel="noreferrer"
/>
),
},
}
)
);
}
};

Expand Down Expand Up @@ -147,5 +168,5 @@ export default connect(
isWooCommerceCoreProfilerFlow( state ),
};
},
{ recordTracksEvent }
{ recordTracksEvent, showErrorNotice: errorNotice }
)( localize( SocialSignupForm ) );

0 comments on commit 59c6952

Please sign in to comment.