diff --git a/client/me/social-login/action-button.jsx b/client/me/social-login/action-button.jsx index b7c91aa3d1556..490f9ad29c285 100644 --- a/client/me/social-login/action-button.jsx +++ b/client/me/social-login/action-button.jsx @@ -28,6 +28,7 @@ class SocialLoginActionButton extends Component { connectSocialUser: PropTypes.func.isRequired, disconnectSocialUser: PropTypes.func.isRequired, socialServiceResponse: PropTypes.object, + redirectUri: PropTypes.string, }; state = { @@ -85,7 +86,7 @@ class SocialLoginActionButton extends Component { }; render() { - const { service, isConnected, isUpdatingSocialConnection, translate } = this.props; + const { service, isConnected, isUpdatingSocialConnection, redirectUri, translate } = this.props; const { fetchingUser } = this.state; @@ -121,8 +122,6 @@ class SocialLoginActionButton extends Component { if ( service === 'apple' ) { const uxMode = config.isEnabled( 'sign-in-with-apple/redirect' ) ? 'redirect' : 'popup'; - const redirectUri = - typeof window !== 'undefined' ? window.location.origin + window.location.pathname : null; return ( @@ -64,6 +66,7 @@ class SocialLogin extends Component { } + redirectUri={ redirectUri } socialServiceResponse={ this.props.socialService === 'apple' ? this.props.socialServiceResponse : null } diff --git a/client/me/social-login/service.jsx b/client/me/social-login/service.jsx index d72f8578a9917..b1e1d0d042236 100644 --- a/client/me/social-login/service.jsx +++ b/client/me/social-login/service.jsx @@ -16,6 +16,7 @@ const SocialLoginService = ( { service, icon, isConnected, + redirectUri, socialConnectionEmail, socialServiceResponse, } ) => ( @@ -29,6 +30,7 @@ const SocialLoginService = ( {
{ // ignore errors - } ); + } ) + .finally( next ); + } else { + next(); + } +} + +function redirectToCalypso( request, response, next ) { + if ( ! request.user_openid_data ) { + return next(); } const originalUrlPath = request.originalUrl.split( '#' )[ 0 ]; const hashString = qs.stringify( { - id_token: idToken, - user_email: userEmail, - user_name: userName, + ...request.user_openid_data, client_id: config( 'apple_oauth_client_id' ), state: request.body.state, } ); @@ -66,6 +77,7 @@ module.exports = function( app ) { return app.post( [ '/log-in/apple/callback', '/start/user', '/me/security/social-login' ], bodyParser.urlencoded(), - loginWithApple + loginWithApple, + redirectToCalypso ); };