From d7512ace72448242b392299cf459c9c72c8dbee5 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 11 Aug 2017 14:48:42 +0300 Subject: Get Google authentication flow working --- src/containers/auth/Login.js | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/containers/auth/Login.js (limited to 'src/containers/auth/Login.js') diff --git a/src/containers/auth/Login.js b/src/containers/auth/Login.js new file mode 100644 index 00000000..358ea7e9 --- /dev/null +++ b/src/containers/auth/Login.js @@ -0,0 +1,56 @@ +import PropTypes from "prop-types"; +import React from "react"; +import GoogleLogin from "react-google-login"; +import {connect} from "react-redux"; +import {completeLogin} from "../../actions/auth"; + +class LoginContainer extends React.Component { + static propTypes = { + visible: PropTypes.bool.isRequired, + onLogin: PropTypes.func.isRequired, + }; + + onAuthResponse(response) { + this.props.onLogin({ + googleId: response.googleId, + authToken: response.accessToken, + expiresAt: response.getAuthResponse().expires_at + }); + } + + render() { + if (!this.props.visible) { + return ; + } + + return ( + + + {' '} + Login with Google + + ); + } +} + +const mapStateToProps = (state, ownProps) => { + return { + visible: ownProps.visible, + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onLogin: (payload) => dispatch(completeLogin(payload)), + }; +}; + +const Login = connect( + mapStateToProps, + mapDispatchToProps +)(LoginContainer); + +export default Login; -- cgit v1.2.3