-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Users should be able to login using Google, Facebook, Twitter [Maintains #164798166]
- Loading branch information
Daniel Lwetabe
authored and
Daniel Lwetabe
committed
May 14, 2019
1 parent
b74be53
commit 4c3031e
Showing
26 changed files
with
410 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
baseURL= | ||
appId= | ||
redirectUri= | ||
googleSocialUrl= | ||
ClientId= | ||
ClientSecret= | ||
AppUrl= | ||
AppId= |
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,7 +1,7 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "stable" | ||
- "9" | ||
|
||
cache: | ||
directories: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import axios from 'axios'; | ||
import { | ||
IS_AUTHENTICATING_WITH_FB_STARTED, | ||
FB_AUTH_DONE_SUCCESS, | ||
} from './types'; | ||
import { AppUrl } from '../components/socialLogin/FacebookConfig'; | ||
|
||
const loginWithFb = token => (dispatch) => { | ||
dispatch({ | ||
type: IS_AUTHENTICATING_WITH_FB_STARTED, | ||
}); | ||
return axios.post(AppUrl, { | ||
user_token: { | ||
auth_token: token, | ||
}, | ||
}).then((resp) => { | ||
dispatch({ | ||
type: FB_AUTH_DONE_SUCCESS, | ||
payload: resp.data.auth_token.token, | ||
}); | ||
localStorage.setItem('accessToken', resp.data.auth_token.token); | ||
document.location.href = '/'; | ||
}); | ||
}; | ||
|
||
export default loginWithFb; |
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,2 @@ | ||
export const IS_AUTHENTICATING_WITH_FB_STARTED = 'IS_AUTHENTICATING_WITH_FB_STARTED'; | ||
export const FB_AUTH_DONE_SUCCESS = 'FB_AUTH_DONE_SUCCESS'; |
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,15 @@ | ||
button.kep-login-facebook { | ||
background-color: #14243B; | ||
font-size: 3.125rem; | ||
border: none; | ||
} | ||
|
||
.fa-facebook { | ||
font-size: 2.1875rem; | ||
border-radius: 1.25rem; | ||
color: #28589c; | ||
} | ||
|
||
button.kep-login-facebook { | ||
padding:0; | ||
} |
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,29 @@ | ||
import React, { Component } from 'react'; | ||
import FacebookLogin from 'react-facebook-login'; | ||
import loginWithFb from '../../actions/facebookActions'; | ||
import store from '../../store'; | ||
import './FaceBook.css'; | ||
|
||
|
||
class FaceBookButton extends Component { | ||
responseFacebook = (response) => { | ||
const FbToken = response.accessToken; | ||
store.dispatch(loginWithFb(FbToken)); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="facebookbutton"> | ||
<FacebookLogin | ||
appId={process.env.appId} | ||
fields="name,email,picture" | ||
callback={this.responseFacebook} | ||
textButton={false} | ||
icon={<i className="fab fa-facebook" />} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const AppId = `${process.env.AppId}`; | ||
export const AppUrl = `${process.env.AppUrl}`; |
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,5 @@ | ||
.fa-google-plus { | ||
font-size: 2.1875rem !important; | ||
color: #CD574B; | ||
cursor: pointer; | ||
} |
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,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import GoogleLogin from 'react-google-login'; | ||
import { ClientId } from './GoogleConfig'; | ||
import './Google.css'; | ||
|
||
const Google = ({ responseGoogle }) => ( | ||
<> | ||
<div className="google-login"> | ||
<GoogleLogin | ||
clientId={ClientId} | ||
render={renderProps => ( | ||
<span | ||
onClick={renderProps.onClick} | ||
disabled={renderProps.disabled} | ||
className="fab fa-google-plus" | ||
role="presentation" | ||
/> | ||
)} | ||
redirectUri={process.env.redirectUri} | ||
onSuccess={responseGoogle} | ||
onFailure={responseGoogle} | ||
/> | ||
</div> | ||
</> | ||
); | ||
|
||
Google.propTypes = { | ||
responseGoogle: PropTypes.func, | ||
}; | ||
|
||
Google.defaultProps = { | ||
responseGoogle: () => {}, | ||
}; | ||
|
||
export default Google; |
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,2 @@ | ||
export const ClientId = `${process.env.ClientId}`; | ||
export const ClientSecret = `${process.env.ClientSecret}`; |
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,45 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import moxios from 'moxios'; | ||
import loginWithFb from '../../../actions/facebookActions'; | ||
import { | ||
IS_AUTHENTICATING_WITH_FB_STARTED, | ||
FB_AUTH_DONE_SUCCESS, | ||
} from '../../../actions/types'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
describe('authentication process', () => { | ||
beforeEach(() => { | ||
moxios.install(); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(); | ||
}); | ||
|
||
it('logs in successfully', () => { | ||
const store = mockStore({}); | ||
moxios.wait(() => { | ||
const requestM = moxios.requests.mostRecent(); | ||
requestM.respondWith({ | ||
status: 200, | ||
response: { | ||
auth_token: { | ||
token: 'test_token', | ||
}, | ||
}, | ||
}); | ||
}); | ||
const expectedActions = [ | ||
{ type: IS_AUTHENTICATING_WITH_FB_STARTED }, | ||
{ | ||
payload: 'test_token', | ||
type: FB_AUTH_DONE_SUCCESS, | ||
}]; | ||
return store.dispatch(loginWithFb('eyJ0eXAiOiJKV1QiLCJ')).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import FaceBookButton from '../FaceBookButton'; | ||
|
||
|
||
describe('Facebook Button Tests', () => { | ||
it('should not regress', () => { | ||
const componentWrapper = shallow(<FaceBookButton />); | ||
const response = { | ||
accessToken: 'testToken', | ||
}; | ||
componentWrapper.instance().responseFacebook(response); | ||
}); | ||
|
||
it('snapshot test', () => { | ||
const componentWrapper = shallow(<FaceBookButton />); | ||
expect(componentWrapper).toMatchSnapshot(); | ||
}); | ||
}); |
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,19 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { shallow } from 'enzyme'; | ||
import GoogleButton from '../GoogleButton'; | ||
import SignUpPage from '../../../pages/Signup/index'; | ||
|
||
describe('Google sign in', () => { | ||
it('should render without crashing', () => { | ||
const wrapper = renderer.create(<GoogleButton />); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('Signup', () => { | ||
it('should should render correctly', () => { | ||
const wrapper = shallow(<SignUpPage />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.