-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(facebook-auth):enable facebook login and signup
- enable redirect upon successful authentication - authenticate user - write auth actions and reducers [Finishes #162553610]
- Loading branch information
1 parent
b58dba3
commit 0a21c77
Showing
18 changed files
with
190 additions
and
37 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import FacebookLogin from 'react-facebook-login/dist/facebook-login-render-props'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const FacebookButton = ({ responseFacebook, request, text }) => ( | ||
<FacebookLogin | ||
appId={process.env.FACEBOOK_APP_ID} | ||
autoLoad={false} | ||
onClick={request} | ||
fields="name,email,picture" | ||
callback={responseFacebook} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
render={renderProps => ( | ||
<button type="button" className="btn btn-primary w-100 facebook-btn" onClick={renderProps.onClick}> | ||
<i className="fab fa-facebook-f mr-2" /> | ||
{text} | ||
</button> | ||
)} | ||
/> | ||
); | ||
|
||
FacebookButton.propTypes = { | ||
responseFacebook: PropTypes.func.isRequired, | ||
request: PropTypes.func.isRequired, | ||
text: PropTypes.string.isRequired | ||
}; | ||
|
||
export default FacebookButton; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,4 @@ const globalReducer = (state = global, action) => { | |
} | ||
}; | ||
|
||
|
||
export default globalReducer; |
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,21 @@ | ||
import { toastr } from 'react-redux-toastr'; | ||
|
||
const loginFacebook = (response, handleLogin, failure) => { | ||
if (!response.id) { | ||
toastr.error('There has been an error from the facebook server. Please try again'); | ||
return failure(['There has been an error from the facebook server. Please try again']); | ||
} | ||
const facebookName = response.name.toString().split(' '); | ||
if (facebookName.length > 2) facebookName.pop(); | ||
const fullName = facebookName.join(' '); | ||
const userObject = { | ||
fullName, | ||
email: response.email, | ||
socialType: 'facebook', | ||
socialId: response.userID, | ||
avatarUrl: response.picture.data.url | ||
}; | ||
return handleLogin(userObject); | ||
}; | ||
|
||
export default loginFacebook; |
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,23 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import FacebookButton from '../../../../src/components/common/FacebookButton'; | ||
|
||
const setup = () => { | ||
const props = { | ||
responseFacebook: jest.fn(), | ||
request: jest.fn(), | ||
text: 'Signup with Facebook' | ||
}; | ||
const wrapper = shallow(<FacebookButton {...props} />); | ||
return { wrapper, props }; | ||
}; | ||
|
||
test('should render facebook button', () => { | ||
const { wrapper } = setup(); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('should render facebook button without crashing', () => { | ||
const { wrapper } = setup(); | ||
expect(wrapper.exists()).toBe(true); | ||
}); |
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.