React native Undefined 不是一个函数(评估 '_app2.default.auth()')



伙计们这是我的React本机应用程序的代码,直到昨天效果很好,Tody我更新了节点模块,并且我将上述代码作为错误。我该如何解决这个问题,我是新手反应本地和燃料。

伙计们,这是我的React本机应用程序的代码,直到昨天效果很好,Tody我更新了节点模块,并且我将上述代码作为错误。我该如何解决这个问题,我是新手反应本地和燃料。

import React from 'react';
import {
  Text,
  View,
  Image,
  TouchableOpacity,
  AsyncStorage,
  TextInput,
  KeyboardAvoidingView,
  ScrollView,
  ActivityIndicator
} from 'react-native';
import { styles } from './Css';
// import * as firebase from "firebase";
// import firebase from '@firebase/app';
// require('firebase/auth');
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
import { GoogleSignin } from 'react-native-google-signin';
var asyncValue;
const auth = firebase.auth();
export default class Login extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      email: '',
      password: '',
      userId: '',
      errorMessage: null,
      animating: false
    };
  }
  navigation1= this.props.navigation
  componentDidMount () {
    this._loadInitialState().done();
    // Activity indicator
    // this.setToggleTimeout()
  }
  componentWillUnmount () {
    clearTimeout(this._timer);
  }
  _loadInitialState = async () => {
    asyncValue = await AsyncStorage.getItem('user');
    // alert("value=" + value)
    if (asyncValue !== null) {
      // this.props.navigation.navigate('SuperMarket1')
    }
    //= ============SignIn With Google==============
    GoogleSignin.configure({
      webClientId: 'webclient id'
      // forceConsentPrompt: true, // if you want to show the authorization prompt at each login
    });
  //= =============================================
  };
  setToggleTimeout () {
    this._timer = setTimeout(() => {
      this.setState({ animating: !this.state.animating });
      this.setToggleTimeout()
      ;
    }, 2000);
  }
  /// ////////////////
  navigate (routeName) {
    this.props.navigator.push({
      name: routeName
    });
  }
  /// ////////////////
  handleLogin = (email, password) => {
    if (this.state.email.length < 1) {
      alert('Enter an Email');
      return;
    }
    if (this.state.email.includes('@') == false) {
      alert('Use an email as Username');
      return;
    }
    if (this.state.password.length < 6) {
      alert('please enter correct password');
      return;
    }
    console.log('uuid= ' + firebase.auth().currentUser.uid);
    auth.signInWithEmailAndPassword(email, password).then((user) => {
      this.props.navigation.navigate('SuperMarket1');
      if (user) {
        // --------------------------Async Test--------------------------
        AsyncStorage.setItem('user', firebase.auth().currentUser.uid);
        console.log('AsyncStorage= ' + asyncValue);
        // --------------------------------------------------------------
      } else {
      }
    })
      .catch(function (error) {
        var errorCode = error.code;
        var errorMessage = error.message;
        if (errorCode === 'auth/wrong-password') {
          alert('Wrong password.');
          return;
        } else {
          alert(errorMessage);
          return;
        }
        console.log(error);
      });
    // //--------------------------Async Test--------------------------
    // AsyncStorage.setItem("user", firebase.auth().currentUser.uid);
    // //--------------------------------------------------------------
  };
  // -------------------------------Temp Functions-----------------
  fb = () => {
    this.props.navigation.navigate('SuperMarket1');
    alert('Curently atuo logged in with Developers FB ID');
  };
  Glg = () => {
    console.log(firebase.auth); // Undefined
    console.log(firebase.default.auth); // Function
    GoogleSignin.hasPlayServices()
      .then(res => {
        GoogleSignin.signIn()
          .then(res => {
            console.log('res:' + res);
            const credential = firebase.auth.GoogleAuthProvider.credential(res.idToken, res.accessToken);
            console.log('res:' + credential);
            return firebase.auth().signInWithCredential(credential);
          })
          .catch(err => {
            console.log(error.code);
          });
      })
      .catch(err => {
        console.log(err);
      });
  };
  twt = () => {
    this.props.navigation.navigate('SuperMarket1');
    alert('Curently atuo logged in with Developers Twt ID');
  };
  // -------------------------------------------------------------
  fgt = () => {
    this.props.navigation('ForgotPassword');
  };
  render () {
    return (
      <View style={styles.container}>
        <ActivityIndicator
          animating={this.state.animating}
          style={[styles.centering, { height: 80 }]}
          size="large"
        />
        <KeyboardAvoidingView style={styles.Top} behavior="padding" enabled>
          <Image
            style={styles.Image}
            source={require('../src/Assets/logo.png')}
          />
        </KeyboardAvoidingView>
        <View style={styles.Second}>
          <View style={styles.Third}>
            <Text style={styles.Textfirst}>Log In</Text>
          </View>
          <View style={styles.Fourth}>
            <View style={styles.Fifth}>
              <Image
                style={styles.Imagesecond}
                source={require('../src/Assets/Profile-xhdpi.png')}
              />
            </View>
            <View style={styles.Sixth}>
              <Text style={styles.Textsecond}>USER/EMAIL</Text>
              <TextInput
                placeholder="user@mail.com                 " style={styles.one} underlineColorAndroid='transparent'
                // --------------value Handler----------------//
                onChangeText={email => this.setState({ email })}
                /// /---------------------------------//
                keyboardType="email-address"
              />
            </View>
          </View>
          <View style={styles.Seventh}>
            <View style={styles.Eighth}>
              <Image
                style={styles.Imagethird}
                source={require('../src/Assets/8-layers-xhdpi.png')}
              />
            </View>
            <View style={styles.ninth}>
              <Text style={styles.Textsecond}>PASSWORD</Text>
              <TextInput style={styles.one} underlineColorAndroid='transparent'
                placeholder="**************                   "
                secureTextEntry={true}
                // --------------value Handler----------------//
                onChangeText={password => this.setState({ password })}
                // ---------------------------------//
              />
            </View>
          </View>
          <View style={styles.Tenth}>
            <Text style={styles.Textfourth}>Forget password?</Text>
            <Text
              style={styles.Textfifth}
              onPress={() => this.props.navigation.navigate('ForgotPassword')}
            >
              {' '}
              Click here
            </Text>
          </View>
          <View style={styles.Eleventh}>
            {/* --------Login With Facebook-------- */}
            <TouchableOpacity onPress={() => this.fb()}>
              <Image
                style={styles.Imagefourth}
                source={require('../src/Assets/3-layers-hdpi.png')}
              />
            </TouchableOpacity>
            {/* --------------------------------- */}
            {/* --------Login With Google-------- */}
            <TouchableOpacity onPress={() => this.Glg()}>
              <Image
                style={styles.Imagefourth}
                source={require('../src/Assets/5-layers-hdpi.png')}
              />
            </TouchableOpacity>
            {/* --------------------------------- */}
            {/* --------Login With Twitter-------- */}
            <TouchableOpacity onPress={() => this.twt()}>
              <Image
                style={styles.Imagefourth}
                source={require('../src/Assets/4-layers-xhdpi.png')}
              />
            </TouchableOpacity>
            {/* --------------------------------- */}
          </View>
          <TouchableOpacity style={styles.Twelth} onPress={() => this.handleLogin(this.state.email, this.state.password)}>
            <View style={styles.Thirteenth}>
              <Text style={styles.Textsixth}>LOG IN</Text>
            </View>
            <View style={styles.Fourteenth}>
              <View style={styles.Fifteenth}>
                <Image
                  style={styles.Imagefifth}
                  source={require('../src/Assets/Path_11.png')}
                />
              </View>
            </View>
          </TouchableOpacity>
          <View style={styles.Sixteenth}>
            <Text style={styles.Textseventh}>Dont have an account?</Text>
            <Text
              style={styles.Texteighth}
              onPress={() => this.props.navigation.navigate('SignUp')}
            >
              Create a new account
            </Text>
          </View>
        </View>
      </View>
    );
  }
}

很可能节点模块文件夹已损坏或实际没有安装所有内容。另一个问题,如果您更新了火箱模块,则某些依赖性存在问题。因此,我将尝试删除node_modules文件夹,然后再次安装所有内容。

还要确保您从firebase文件中导出了auth变量,我认为这就像firebase助手。

如果重新安装不起作用,请发布您的包裹和firebase文件。

注意:我将从您粘贴的代码中删除WebClient ID和其他一些信息。

相关内容

  • 没有找到相关文章

最新更新