-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- implement functionality to get access token from facebook/ google - include social media icons on both signup and sign in pages - send login request to ah backend using access token and provider details - show spinner when logging in - disable buttons after response - update failing tests - add tests for social login - add documentation [Delivers #165305224]
- Loading branch information
Showing
18 changed files
with
556 additions
and
26 deletions.
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ module.exports = { | |
jsxBracketSameLine: false, | ||
tabWidth: 2, | ||
semi: true, | ||
// arrowParens: 'always', | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Shared */ | ||
.loginBtn { | ||
box-sizing: border-box; | ||
position: relative; | ||
margin: 0.2em; | ||
padding: 0 15px 0 46px; | ||
border: none; | ||
text-align: left; | ||
line-height: 34px; | ||
white-space: nowrap; | ||
border-radius: 0.2em; | ||
font-size: 16px; | ||
color: #fff; | ||
width: -webkit-fill-available; | ||
text-align: -webkit-center; | ||
} | ||
.loginBtn:before { | ||
content: ''; | ||
box-sizing: border-box; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 34px; | ||
height: 100%; | ||
} | ||
.loginBtn:focus { | ||
outline: none; | ||
} | ||
.loginBtn:active { | ||
box-shadow: inset 0 0 0 32px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
/* Facebook */ | ||
.loginBtn--facebook { | ||
background-color: #4c69ba; | ||
background-image: linear-gradient(#4c69ba, #3b55a0); | ||
text-shadow: 0 -1px 0 #354c8c; | ||
} | ||
.loginBtn--facebook:before { | ||
border-right: #364e92 1px solid; | ||
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_facebook.png') 6px 6px | ||
no-repeat; | ||
} | ||
.loginBtn--facebook:hover, | ||
.loginBtn--facebook:focus { | ||
background-color: #5b7bd5; | ||
background-image: linear-gradient(#5b7bd5, #4864b1); | ||
} | ||
|
||
/* Google */ | ||
.loginBtn--google { | ||
background: #dd4b39; | ||
} | ||
.loginBtn--google:before { | ||
border-right: #bb3f30 1px solid; | ||
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_google.png') 6px 6px | ||
no-repeat; | ||
} | ||
.loginBtn--google:hover, | ||
.loginBtn--google:focus { | ||
background: #e74b37; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { withRouter } from 'react-router-dom'; | ||
import FacebookLogin from 'react-facebook-login/dist/facebook-login-render-props'; | ||
import { GoogleLogin } from 'react-google-login'; | ||
import { UserSocialLogin } from '../../redux/actions/loginActions'; | ||
import { errorToast } from '../../helpers'; | ||
import '../../assets/styles/social.scss'; | ||
|
||
class SocialLogin extends Component { | ||
state = { | ||
isClicked: false, | ||
}; | ||
|
||
/* | ||
* componentClicked: | ||
* changes state to avoid double button click | ||
*/ | ||
componentClicked = () => { | ||
this.setState({ | ||
isClicked: true, | ||
}); | ||
}; | ||
|
||
/* | ||
* responseFacebook: | ||
* gets response from Facebook and calls login reducer | ||
*/ | ||
responseFacebook = response => { | ||
this.setState({ | ||
isClicked: true, | ||
}); | ||
const { UserSocialLogin, history } = this.props; | ||
UserSocialLogin({ provider: 'facebook', access_token: response.accessToken }, history); | ||
}; | ||
|
||
/* | ||
* googleResponse: | ||
* gets response from Google and calls login reducer | ||
*/ | ||
googleResponse = response => { | ||
this.setState({ | ||
isClicked: true, | ||
}); | ||
const { UserSocialLogin, history } = this.props; | ||
UserSocialLogin({ provider: 'google-oauth2', access_token: response.accessToken }, history); | ||
}; | ||
|
||
/* | ||
* onFailure: | ||
* Displays error message in case of failure | ||
*/ | ||
onFailure = error => { | ||
errorToast('Oops! something went wrong, please try again'); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div data-set="SocialLoginDiv" className="sld"> | ||
<FacebookLogin | ||
appId="409869986516596" | ||
autoLoad={false} | ||
fields="name,email,picture" | ||
callback={this.responseFacebook} | ||
onClick={this.componentClicked} | ||
isDisabled={this.state.isClicked} | ||
render={renderProps => ( | ||
<button | ||
className="loginBtn loginBtn--facebook" | ||
id="facebookLogin" | ||
onClick={renderProps.onClick} | ||
> | ||
Login with Facebook | ||
</button> | ||
)} | ||
/> | ||
|
||
<GoogleLogin | ||
clientId="857285911538-6jchs8qlak94ek13roke22h2vncbvn5a.apps.googleusercontent.com" | ||
render={renderProps => ( | ||
<button | ||
className="loginBtn loginBtn--google" | ||
id="googleLogin" | ||
onClick={renderProps.onClick} | ||
disabled={renderProps.disabled} | ||
> | ||
Login with Google | ||
</button> | ||
)} | ||
onSuccess={this.googleResponse} | ||
onFailure={this.onFailure} | ||
disabled={this.state.isClicked} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
myState: state, | ||
}); | ||
|
||
const mapDispatchToProps = () => ({ | ||
UserSocialLogin, | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps(), | ||
)(withRouter(SocialLogin)); |
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
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
Oops, something went wrong.