Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Google button disabled after first display #19357

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
} )
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole approach for fixing that issue was suggested here.

)
.catch( error => {
this.initialized = null;
Expand Down