|
@@ -2,22 +2,45 @@ import React, { Component } from 'react'
|
|
|
import { connect } from 'react-redux';
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
|
-import * as actions from './../../actions'
|
|
|
+import { signInRequest } from './../../actions/auth/signIn'
|
|
|
+import { signUpRequest } from './../../actions/auth/signUp'
|
|
|
|
|
|
-console.log(...actions.default)
|
|
|
+import { auth, googleAuthProvider } from '../../firebase_config'
|
|
|
|
|
|
class AuthPage extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
+ this.state = {
|
|
|
+ user: null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount() {
|
|
|
+ auth.onAuthStateChanged(user => this.setState({ user }))
|
|
|
+ }
|
|
|
+
|
|
|
+ authRequest = () => {
|
|
|
+ auth.signInWithPopup(googleAuthProvider)
|
|
|
+ .then(res => {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ user: res.user
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
const { } = this.props; //
|
|
|
+ const { user } = this.state; //
|
|
|
+
|
|
|
+ console.log("<AuthPage> - props", this.props);
|
|
|
+
|
|
|
|
|
|
return (
|
|
|
<div className="auth-page">
|
|
|
- Hi there
|
|
|
- {console.log("<AuthPage> - props", this.props)}
|
|
|
+ <h1>{user && user.displayName}</h1>
|
|
|
+ <button onClick={this.authRequest} disabled={user ? true : false}>Auth</button>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
@@ -25,8 +48,13 @@ class AuthPage extends Component {
|
|
|
|
|
|
const
|
|
|
mapStateToProps = state => ({
|
|
|
- ...state.logIn
|
|
|
+ signInState: {
|
|
|
+ ...state.signIn
|
|
|
+ },
|
|
|
+ signUpState: {
|
|
|
+ ...state.signUp
|
|
|
+ }
|
|
|
}),
|
|
|
- mapDispatchToProps = dispatch => bindActionCreators({ ...actions }, dispatch);
|
|
|
+ mapDispatchToProps = dispatch => bindActionCreators({ signInRequest, signUpRequest }, dispatch);
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AuthPage)
|