分享
三行代码  ›  专栏  ›  技术社区  ›  Susana Esparza

错误:电子邮件地址格式错误-React native-Firebase

  •  0
  • Susana Esparza  · 技术社区  · 1 周前

    我正在尝试使用firebase在react native中创建登录应用程序,此时我尝试打开应用程序时,一个警报显示“错误:电子邮件地址格式错误”。

    登录.js

    import React, { useState } from 'react';
    import { Text, View, TouchableHighlight, TextInput } from 'react-native';
    import firebaseService from '../../services/firebase';
    import Main from '../main/Main';
    import styles from './styles';
    
    const Login = ({navigation}) => {
    
      const[user, setUser] = useState('');
      const[pass, setPass] = useState('');
    
      const onPressLogin = async () => {
        try{
          await firebaseService.login(user, pass);
          navigation.navigate(Main);
        } catch (e) {
          alert(e);
        }
      }
    
      return (
        <View style={styles.container}>
          <View>
            <TextInput
              placeholder="Email"
              value={user} 
              onChange = {(e) => setUser(e.nativeEvent.text)}
              style={styles.inputText}
            />
            <TextInput 
              placeholder="Password" 
              value={pass} 
              onChange = {(e) => setPass(e.nativeEvent.text)}
              style={styles.inputText}
            />
          </View>
          <TouchableHighlight style={[styles.button, styles.loginButton]}onPress={onPressLogin()}>
            <Text style={styles.textButton}>Login</Text>
          </TouchableHighlight>
          <TouchableHighlight style={[styles.button, styles.signUpButton]} onPress={() => navigation.navigate('SignUp')}>
            <Text style={styles.textButton}>Create new user</Text>
          </TouchableHighlight>
        </View>
      );
    }
    
    export default Login;
    

    import * as firebase from "firebase/app";
    import 'firebase/firebase-firestore';
    import 'firebase/firebase-auth';
    
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    const firebaseConfig = {
        apiKey: "*******",
        authDomain: "*******",
        databaseURL: "*******",
        projectId: "*******",
        storageBucket: "*******",
        messagingSenderId: "*******",
        appId: "*******",
        measurementId: "*******"
      }
    
      class Firebase {
          constructor(){
              firebase.initializeApp(firebaseConfig);
              this.auth = firebase.auth();
          }
    
          login = (email, pass) => {
            return this.auth.signInWithEmailAndPassword(email, pass);
          }
      }
    
      const firebaseService = new Firebase();
      export default firebaseService;
    
    1 回复  |  直到 1 周前
        1
  •  0
  •   Horst    1 周前

    因为你是在向 onPress

          <TouchableHighlight style={[styles.button, styles.loginButton]}onPress={onPressLogin()}>
    

          <TouchableHighlight style={[styles.button, styles.loginButton]}onPress={onPressLogin}>