用firebase登录反应本地

时间:2020-06-30 08:36:29

标签: firebase react-native

我是新来对本机做出反应的,我在登录时遇到了问题。即时通讯使用Firebase进行数据库登录,但注册后似乎无法登录。我创建的用户出现在数据库中,但是当我尝试使用那些凭据登录时,系统会告诉我找不到用户

import React, { useState } from 'react'
    import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native'
    import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
    import styles from './styles';
    import { firebase } from '../../firebase/config'
    
    export default function LoginScreen({navigation}) {
        const [email, setEmail] = useState('')
        const [password, setPassword] = useState('')
    
        const onFooterLinkPress = () => {
            navigation.navigate('Registration')
        }
    
        const onLoginPress = () => {
            firebase
                .auth()
                .signInWithEmailAndPassword(email, password)
                .then((response) => {
                    const uid = response.user.uid
                    const usersRef = firebase.firestore().collection('users')
                    usersRef
                        .doc(uid)
                        .get()
                        .then(firestoreDocument => {
                            if (!firestoreDocument.exists) {
                                alert("User does not exist anymore.")
                                return;
                            }
                            const user = firestoreDocument.data()
                            navigation.navigate('Home', {user: user})
                        })
                        .catch(error => {
                            alert(error)
                        });
                })
                .catch(error => {
                    alert(error)
                })
        }
    
        return (
            <View style={styles.container}>
                <KeyboardAwareScrollView
                    style={{ flex: 1, width: '100%' }}
                    keyboardShouldPersistTaps="always">
                    <Image
                        style={styles.logo}
                        source={require('../../../assets/icon.png')}
                    />
                    <TextInput
                        style={styles.input}
                        placeholder='E-mail'
                        placeholderTextColor="#aaaaaa"
                        onChangeText={(text) => setEmail(text)}
                        value={email}
                        underlineColorAndroid="transparent"
                        autoCapitalize="none"
                    />
                    <TextInput
                        style={styles.input}
                        placeholderTextColor="#aaaaaa"
                        secureTextEntry
                        placeholder='Password'
                        onChangeText={(text) => setPassword(text)}
                        value={password}
                        underlineColorAndroid="transparent"
                        autoCapitalize="none"
                    />
                    <TouchableOpacity
                        style={styles.button}
                        onPress={() => onLoginPress()}>
                        <Text style={styles.buttonTitle}>Log in</Text>
                    </TouchableOpacity>
                    <View style={styles.footerView}>
                        <Text style={styles.footerText}>Don't have an account? <Text onPress={onFooterLinkPress} style={styles.footerLink}>Sign up</Text></Text>
                    </View>
                </KeyboardAwareScrollView>
            </View>
        )
    }

当我尝试登录时,我收到一条错误消息,尽管在Firebase数据库中提供了帐户详细信息,但仍找不到用户

0 个答案:

没有答案