Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { withRouter } from 'react-router-dom';
  3. import { bindActionCreators } from 'redux';
  4. import { connect } from 'react-redux';
  5. import FbApp from '../../modules/firebase-app';
  6. import * as userActions from '../../actions/usermanagement/usermanagement';
  7. import Login from '../../components/user-management/login';
  8.  
  9. const auth = FbApp.auth();
  10.  
  11. class LoginContainer extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. loginError: null
  16. }
  17. this.signIn = this.signIn.bind(this);
  18. }
  19. componentWillMount() {
  20. if (this.props.loggedIn) {
  21. this.props.history.push("/");
  22. }
  23. }
  24. componentWillUnmount(){
  25.  
  26. }
  27. signIn(signInState) {
  28. //Login Code
  29. const promise = auth.signInWithEmailAndPassword(signInState.email, signInState.password);
  30. promise.then(result => {
  31. this.props.changeLoggedInStatus(true);
  32. this.props.changeEmail(signInState.email);
  33. this.props.changeUserId(result.uid);
  34. var usersRef = FbApp.database().ref('users');
  35. usersRef.child(result.uid).child("username").on('value', (snap) => {
  36. var username = snap.val();
  37. if (username) {
  38. this.props.changeUsername(username);
  39. this.setState({
  40. email: '',
  41. password: ''
  42. });
  43. this.props.history.push('/');
  44. } else {
  45. this.props.history.push('/create-username');
  46. }
  47. });
  48. }).catch(e => {
  49. console.log(e.message);
  50. this.setState({
  51. loginError: e.message
  52. });
  53. });
  54. }
  55. render() {
  56. return (
  57. <Login signIn={this.signIn} loginError={this.state.loginError} />
  58. );
  59. }
  60. }
  61.  
  62. function mapStateToProps(state) {
  63. return {
  64. userName: state.user.userName,
  65. email: state.user.email,
  66. loggedIn: state.user.loggedIn,
  67. userId: state.user.userId
  68. }
  69. }
  70. function mapDispatchToProps(dispatch) {
  71. return bindActionCreators(userActions, dispatch);
  72. }
  73.  
  74. export default connect(mapStateToProps, mapDispatchToProps)(LoginContainer);
  75.  
  76. 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