Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import { withRouter } from 'react-router-dom';
- import { bindActionCreators } from 'redux';
- import { connect } from 'react-redux';
- import FbApp from '../../modules/firebase-app';
- import * as userActions from '../../actions/usermanagement/usermanagement';
- import Login from '../../components/user-management/login';
- const auth = FbApp.auth();
- class LoginContainer extends Component {
- constructor(props) {
- super(props);
- this.state = {
- loginError: null
- }
- this.signIn = this.signIn.bind(this);
- }
- componentWillMount() {
- if (this.props.loggedIn) {
- this.props.history.push("/");
- }
- }
- componentWillUnmount(){
- }
- signIn(signInState) {
- //Login Code
- const promise = auth.signInWithEmailAndPassword(signInState.email, signInState.password);
- promise.then(result => {
- this.props.changeLoggedInStatus(true);
- this.props.changeEmail(signInState.email);
- this.props.changeUserId(result.uid);
- var usersRef = FbApp.database().ref('users');
- usersRef.child(result.uid).child("username").on('value', (snap) => {
- var username = snap.val();
- if (username) {
- this.props.changeUsername(username);
- this.setState({
- email: '',
- password: ''
- });
- this.props.history.push('/');
- } else {
- this.props.history.push('/create-username');
- }
- });
- }).catch(e => {
- console.log(e.message);
- this.setState({
- loginError: e.message
- });
- });
- }
- render() {
- return (
- <Login signIn={this.signIn} loginError={this.state.loginError} />
- );
- }
- }
- function mapStateToProps(state) {
- return {
- userName: state.user.userName,
- email: state.user.email,
- loggedIn: state.user.loggedIn,
- userId: state.user.userId
- }
- }
- function mapDispatchToProps(dispatch) {
- return bindActionCreators(userActions, dispatch);
- }
- export default connect(mapStateToProps, mapDispatchToProps)(LoginContainer);
- Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the LoginContainer component.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement