summaryrefslogtreecommitdiff
path: root/src/containers/auth
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-11 14:48:42 +0300
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:37 +0200
commitd7512ace72448242b392299cf459c9c72c8dbee5 (patch)
tree37ce113d5d47440139bfe357e9ad547063cd44f7 /src/containers/auth
parent737ce62470a13ae153788207719396e107252955 (diff)
Get Google authentication flow working
Diffstat (limited to 'src/containers/auth')
-rw-r--r--src/containers/auth/Login.js56
-rw-r--r--src/containers/auth/Logout.js20
2 files changed, 76 insertions, 0 deletions
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 <span/>;
+ }
+
+ return (
+ <GoogleLogin
+ clientId="311799954046-jv2inpg9nu7m0avcg6gulvkuvfgbtgb4.apps.googleusercontent.com"
+ onSuccess={this.onAuthResponse.bind(this)}
+ onFailure={this.onAuthResponse.bind(this)}>
+ <span className='fa fa-google'/>
+ {' '}
+ <span>Login with Google</span>
+ </GoogleLogin>
+ );
+ }
+}
+
+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;
diff --git a/src/containers/auth/Logout.js b/src/containers/auth/Logout.js
new file mode 100644
index 00000000..8d329c1f
--- /dev/null
+++ b/src/containers/auth/Logout.js
@@ -0,0 +1,20 @@
+import {connect} from "react-redux";
+import {logOut} from "../../actions/auth";
+import LogoutButton from "../../components/navigation/LogoutButton";
+
+const mapStateToProps = state => {
+ return {};
+};
+
+const mapDispatchToProps = dispatch => {
+ return {
+ onLogout: () => dispatch(logOut()),
+ };
+};
+
+const Logout = connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(LogoutButton);
+
+export default Logout;