-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Social Signup: Handle the case where users block third-party cookies/data #13983
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a7ae224
Show a message when 3rd party cookies are disabled
pento 6cdca3b
Social Signup: update copy when third-party cookies are blocked
fabianapsimoes 1791649
Clean up the code a little bit.
pento a25780c
Tweak the copy.
pento 8f37861
Add a disabled-style Google logo for when the Google button is disabled.
pento a5f8d5b
Reject the promise in case of a idpiframe_initialization_failed error
Tug acafb76
Sign up: Show Google service error block only when there is an error
gziolo e258338
Updated info text for social buttons.
pento b8c4049
Change the error message to a popover
pento e34bad4
Remove an unnecessary newline
pento 46d8aa6
Always associate the Popover with the social button
pento 111f090
Switch from `current()` to `currentTarget` to find the button when ho…
pento 8084b81
Revert the form text changes from fc3acc4 and 4cf9438
pento 8f0d8ba
When testing, the `Login` form must be loaded after `useFakeDom()`, b…
pento File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,6 @@ | |
margin: 0 0 10px; | ||
width: 100%; | ||
} | ||
|
||
svg { | ||
margin-top: -2px; | ||
} | ||
} | ||
|
||
.signup-form__notice.notice { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,12 @@ import React, { Component, PropTypes } from 'react'; | |
import { loadScript } from 'lib/load-script'; | ||
import { localize } from 'i18n-calypso'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Popover from 'components/popover'; | ||
import { preventWidows } from 'lib/formatting'; | ||
|
||
class GoogleLoginButton extends Component { | ||
static propTypes = { | ||
clientId: PropTypes.string.isRequired, | ||
|
@@ -19,11 +25,20 @@ class GoogleLoginButton extends Component { | |
fetchBasicProfile: true, | ||
}; | ||
|
||
state = { | ||
error: '', | ||
showError: false, | ||
errorRef: null, | ||
}; | ||
|
||
constructor( props ) { | ||
super( props ); | ||
|
||
this.initialized = null; | ||
|
||
this.handleClick = this.handleClick.bind( this ); | ||
this.showError = this.showError.bind( this ); | ||
this.hideError = this.hideError.bind( this ); | ||
} | ||
|
||
componentDidMount() { | ||
|
@@ -45,6 +60,10 @@ class GoogleLoginButton extends Component { | |
return this.initialized; | ||
} | ||
|
||
this.setState( { error: '' } ); | ||
|
||
const { translate } = this.props; | ||
|
||
this.initialized = this.loadDependency() | ||
.then( gapi => new Promise( resolve => gapi.load( 'client:auth2', resolve ) ).then( () => gapi ) ) | ||
.then( gapi => gapi.client.init( { | ||
|
@@ -56,6 +75,11 @@ class GoogleLoginButton extends Component { | |
).catch( error => { | ||
this.initialized = null; | ||
|
||
if ( 'idpiframe_initialization_failed' === error.error ) { | ||
// This error is caused by 3rd party cookies being blocked. | ||
this.setState( { error: translate( 'Please enable "third-party cookies" to connect your Google account.' ) } ); | ||
} | ||
|
||
return Promise.reject( error ); | ||
} ); | ||
|
||
|
@@ -65,6 +89,15 @@ class GoogleLoginButton extends Component { | |
handleClick( event ) { | ||
event.preventDefault(); | ||
|
||
if ( this.state.error ) { | ||
this.setState( { | ||
showError: ! this.state.showError, | ||
errorRef: event.currentTarget, | ||
} ); | ||
|
||
return; | ||
} | ||
|
||
const { responseHandler } = this.props; | ||
|
||
// Handle click async if the library is not loaded yet | ||
|
@@ -74,27 +107,69 @@ class GoogleLoginButton extends Component { | |
this.initialize().then( gapi => gapi.auth2.getAuthInstance().signIn( { prompt: 'select_account' } ).then( responseHandler ) ); | ||
} | ||
|
||
showError( event ) { | ||
if ( ! this.state.error ) { | ||
return; | ||
} | ||
|
||
this.setState( { | ||
showError: true, | ||
errorRef: event.currentTarget, | ||
} ); | ||
} | ||
|
||
hideError() { | ||
this.setState( { showError: false } ); | ||
} | ||
|
||
render() { | ||
let classes = 'social-buttons__button button'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is: import classNames from 'classnames';
classNames( 'social-buttons__button', 'button', { disabled: this.state.error } ); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So many magic functions. 😁 |
||
if ( this.state.error ) { | ||
classes += ' disabled'; | ||
} | ||
|
||
return ( | ||
<button className="button" onClick={ this.handleClick }> | ||
<svg className="social-buttons__logo" width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | ||
<div> | ||
<button className={ classes } onMouseOver={ this.showError } onMouseOut={ this.hideError } onClick={ this.handleClick }> | ||
{ /* eslint-disable max-len */ } | ||
<g fill="none" fillRule="evenodd"> | ||
<path d="M19.6 10.227c0-.709-.064-1.39-.182-2.045H10v3.868h5.382a4.6 4.6 0 0 1-1.996 3.018v2.51h3.232c1.891-1.742 2.982-4.305 2.982-7.35z" fill="#4285F4" /> | ||
<path d="M10 20c2.7 0 4.964-.895 6.618-2.423l-3.232-2.509c-.895.6-2.04.955-3.386.955-2.605 0-4.81-1.76-5.595-4.123H1.064v2.59A9.996 9.996 0 0 0 10 20z" fill="#34A853" /> | ||
<path d="M4.405 11.9c-.2-.6-.314-1.24-.314-1.9 0-.66.114-1.3.314-1.9V5.51H1.064A9.996 9.996 0 0 0 0 10c0 1.614.386 3.14 1.064 4.49l3.34-2.59z" fill="#FBBC05" /> | ||
<path d="M10 3.977c1.468 0 2.786.505 3.823 1.496l2.868-2.868C14.959.99 12.695 0 10 0 6.09 0 2.71 2.24 1.064 5.51l3.34 2.59C5.192 5.736 7.396 3.977 10 3.977z" fill="#EA4335" /> | ||
<svg className="social-buttons__logo enabled" width="20" height="20" viewBox="0 0 20 20"xmlns="http://www.w3.org/2000/svg"> | ||
<g fill="none" fillRule="evenodd"> | ||
<path d="M19.6 10.227c0-.709-.064-1.39-.182-2.045H10v3.868h5.382a4.6 4.6 0 0 1-1.996 3.018v2.51h3.232c1.891-1.742 2.982-4.305 2.982-7.35z" fill="#4285F4" /> | ||
<path d="M10 20c2.7 0 4.964-.895 6.618-2.423l-3.232-2.509c-.895.6-2.04.955-3.386.955-2.605 0-4.81-1.76-5.595-4.123H1.064v2.59A9.996 9.996 0 0 0 10 20z" fill="#34A853" /> | ||
<path d="M4.405 11.9c-.2-.6-.314-1.24-.314-1.9 0-.66.114-1.3.314-1.9V5.51H1.064A9.996 9.996 0 0 0 0 10c0 1.614.386 3.14 1.064 4.49l3.34-2.59z" fill="#FBBC05" /> | ||
<path d="M10 3.977c1.468 0 2.786.505 3.823 1.496l2.868-2.868C14.959.99 12.695 0 10 0 6.09 0 2.71 2.24 1.064 5.51l3.34 2.59C5.192 5.736 7.396 3.977 10 3.977z" fill="#EA4335" /> | ||
</g> | ||
</svg> | ||
|
||
<svg className="social-buttons__logo disabled" width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> | ||
<g fill="none" fillRule="evenodd"> | ||
<path d="M19.6 10.227c0-.709-.064-1.39-.182-2.045H10v3.868h5.382a4.6 4.6 0 0 1-1.996 3.018v2.51h3.232c1.891-1.742 2.982-4.305 2.982-7.35z" fill="#e9eff3" /> | ||
<path d="M10 20c2.7 0 4.964-.895 6.618-2.423l-3.232-2.509c-.895.6-2.04.955-3.386.955-2.605 0-4.81-1.76-5.595-4.123H1.064v2.59A9.996 9.996 0 0 0 10 20z" fill="#e9eff3" /> | ||
<path d="M4.405 11.9c-.2-.6-.314-1.24-.314-1.9 0-.66.114-1.3.314-1.9V5.51H1.064A9.996 9.996 0 0 0 0 10c0 1.614.386 3.14 1.064 4.49l3.34-2.59z" fill="#e9eff3" /> | ||
<path d="M10 3.977c1.468 0 2.786.505 3.823 1.496l2.868-2.868C14.959.99 12.695 0 10 0 6.09 0 2.71 2.24 1.064 5.51l3.34 2.59C5.192 5.736 7.396 3.977 10 3.977z" fill="#e9eff3" /> | ||
</g> | ||
</svg> | ||
{ /* eslint-enable max-len */ } | ||
</g> | ||
</svg> | ||
|
||
<span className="social-buttons__service-name"> | ||
{ this.props.translate( 'Continue with %(service)s', { | ||
args: { service: 'Google' }, | ||
comment: '%(service)s is the name of a Social Network, e.g. "Google", "Facebook", "Twitter" ...' | ||
} ) } | ||
</span> | ||
</button> | ||
|
||
<span className="social-buttons__service-name"> | ||
{ this.props.translate( 'Continue with %(service)s', { | ||
args: { service: 'Google' }, | ||
comment: '%(service)s is the name of a Social Network, e.g. "Google", "Facebook", "Twitter" ...' | ||
} ) } | ||
</span> | ||
</button> | ||
|
||
<Popover | ||
id="social-buttons__error" | ||
className="social-buttons__error" | ||
isVisible={ this.state.showError } | ||
onClose={ this.hideError } | ||
position="top" | ||
context={ this.state.errorRef } | ||
> | ||
{ preventWidows( this.state.error ) } | ||
</Popover> | ||
</div> | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
/*rtl:ignore*/ | ||
|
||
.social-buttons__button { | ||
svg { | ||
margin-top: -2px; | ||
|
||
&.disabled { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
.social-buttons__button.disabled { | ||
svg.enabled { | ||
display: none; | ||
} | ||
|
||
svg.disabled { | ||
display: inline; | ||
} | ||
} | ||
|
||
.social-buttons__logo { | ||
vertical-align: middle; | ||
} | ||
|
||
.social-buttons__service-name { | ||
margin-left: 9px; | ||
} | ||
|
||
.social-buttons__error { | ||
.popover__inner { | ||
padding: 10px; | ||
max-width: 200px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be initialized more than once? If not then we can remove this state change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep,
initialize()
can be called multiple times -this.initialized
won't be set until thegapi
instance is properly initialised.