0

When i click the login button first time i am getting value is "undefined", after second click it showing exact value what i am excepting. My requirement is i need check valid user name and PASSWORD, if it is correct then get the details of particular user, once data is retrieved i need to navigate another page, Below is code, Please help how to call:

import PropTypes from "prop-types";
import React, { Component } from "react";
import {
  View,
  Text,
  Button,
  TouchableOpacity,
  TextInput,
  StyleSheet,
  NavigationActions
} from "react-native";
    import firebase from "firebase";

    export class Login extends Component {
      state = {
        email: "xxxxxx",
        password: "123456",
        items: [],
        userData: [],
        currentUser: null,
        role: ""
      };


      login = (email, pass) => {

        this.validateFirebase(email, pass);
      };
      validateFirebase = (email, pass) => {
        firebase
          .auth()
          .signInWithEmailAndPassword("xxxxxx.com", "123456")
          .then(() => {

            {this.forgotPasswordForm()}
          })
          .catch(function(error) {
            console.error("Error: ", error);
          });
      };

        // Create a function that will update the state in parent
        forgotPasswordForm = () => {
          const { currentUser } = firebase.auth();

            let u_ref = currentUser.uid;
            let userEmail = currentUser.email;
          firebase.database()
          .ref("users_ids/0")
          .once("value")
          .then(function(snapshot) {
            snapshot.forEach(function(childSnapshot) {
              var key = childSnapshot.key;
              var childData = childSnapshot.val();
              if (key ==  u_ref) {
                hello = childData.role;
               if(hello == 'employee'){
                this.props.navigation.navigate("driverloginScreen");
               }
              }
            });
          });


        }





      render() {
        return (
          <View style={styles.container}>
            <TextInput
              style={styles.input}
              underlineColorAndroid="transparent"
              placeholder="Email"
              placeholderTextColor="black"
              autoCapitalize="none"
              onChangeText={this.handleEmail}
            />

            <TextInput
              style={styles.input}
              underlineColorAndroid="transparent"
              placeholder="Password"
              placeholderTextColor="black"
              autoCapitalize="none"
              onChangeText={this.handlePassword}
            />

            <TouchableOpacity
              style={styles.submitButton}
              onPress={() => this.login(this.state.email, this.state.password)}
            >
              <Text style={styles.submitButtonText}> Submit </Text>
            </TouchableOpacity>
          </View>
        );
      }
    }
    export default Login;
  • can you print the email and password value for each click? Will it write the current email and password for first time? – eemrah Dec 12 '18 at 12:47
  • Yes, passing correct mail id and password only – Indira Maddikunta Dec 12 '18 at 12:53
  • Hey again, I would like to say something, by the way I ran the code and debug pass and email, it works well, when you pass wrong email and password, what is debugging on error callback? also why you always send it forgotPassword on success callback? – eemrah Dec 12 '18 at 19:37
  • @elia could you please post the solution navigate the second after fetch details – Indira Maddikunta Dec 13 '18 at 13:35
  • i did not change anything, also not checked firebase section because there is no config files for firebase – eemrah Dec 13 '18 at 14:48

0 Answers0