Skip to content

Commit

Permalink
Merge pull request #19357 from Automattic/fix/google-button
Browse files Browse the repository at this point in the history
Fix Google button disabled after first display
  • Loading branch information
stephanethomas authored Nov 6, 2017
2 parents eff8222 + d068afd commit 9a5a377
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions client/components/social-buttons/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,28 @@ class GoogleLoginButton extends Component {
.then( gapi =>
gapi.client
.init( {
client_id: this.props.clientId,
scope: this.props.scope,
fetch_basic_profile: this.props.fetchBasicProfile,
ux_mode: this.props.uxMode,
redirect_uri: this.props.redirectUri,
} )
.then( () => {
this.setState( { isDisabled: false } );

const googleAuth = gapi.auth2.getAuthInstance();
const currentUser = googleAuth.currentUser.get();

// handle social authentication response from a redirect-based oauth2 flow
if ( currentUser && this.props.uxMode === 'redirect' ) {
this.props.responseHandler( currentUser, false );
}

return gapi; // don't try to return googleAuth here, it's a thenable but not a valid promise
} )
.then( () =>
gapi.auth2.init( {
client_id: this.props.clientId,
scope: this.props.scope,
} ).then( () => {
this.setState( { isDisabled: false } );

const googleAuth = gapi.auth2.getAuthInstance();
const currentUser = googleAuth.currentUser.get();

// handle social authentication response from a redirect-based oauth2 flow
if ( currentUser && this.props.uxMode === 'redirect' ) {
this.props.responseHandler( currentUser, false );
}

return gapi; // don't try to return googleAuth here, it's a thenable but not a valid promise
} )
)
)
.catch( error => {
this.initialized = null;
Expand Down

0 comments on commit 9a5a377

Please sign in to comment.