如何通过react native判断Firebase auth in Signup按钮中是否存在用户?

This is my Login Page Code:

export default class Login extends Component {
    constructor(props) {
        super(props)
        this.state = {
            email: '',
            password: '',
            response: ''
        }
        this.signUp = this.signUp.bind(this)
        this.login = this.login.bind(this)
    }

    async signUp() {
        try {
            await firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)
            this.setState({
                response: 'Account Created!'
            })
            setTimeout(() => {
                this.props.navigator.push({
                    id: 'App'
                })
            }, 500)
        } catch (error) {
            this.setState({
                response: error.toString()
            })
        }
    }
    async login() {
        try {
            await firebase.auth().signInWithEmailAndPassword(this.state.email, this.state.password)
            this.setState({
                response: 'user login in'
            })

            setTimeout(() => {
                this.props.navigator.push({
                    id: 'App'
                })
            })

        } catch (error) {
            this.setState({
                response: error.toString()
            })
        }
    }

    render() {
        return (
            <View style={styles.container}>
                <View style={styles.containerInputes}>
                    <TextInput
                        placeholderTextColor="gray"
                        placeholder="Email"
                        style={styles.inputText}
                        onChangeText={(email) => this.setState({ email })}
                    />
                    <TextInput
                        placeholderTextColor="gray"
                        placeholder="Password"
                        style={styles.inputText}
                        password={true}
                        secureTextEntry={true}
                        onChangeText={(password) => this.setState({ password })}
                    />
                </View>
                <TouchableHighlight
                    onPress={this.login}
                    style={[styles.loginButton, styles.button]}
                >
                    <Text
                        style={styles.textButton}
                    >Login</Text>
                </TouchableHighlight>
                <TouchableHighlight
                    onPress={this.signUp}
                    style={[styles.loginButton, styles.button]}
                >
                    <Text
                        style={styles.textButton}
                    >Signup</Text>
                </TouchableHighlight>
            </View>
        )
    }
}

推荐答案

您需要使用FetchSignInMethodForEmail API.它接收一封邮箱并返回一个promise ,该promise 与链接到该邮箱的Provider 列表(如果已注册)一致:

React-native相关问答推荐

React native React native下拉 Select 器下拉列表不透明问题

react native调用fetch后如何使用Async Storage在本地保存数据?

错误:图片:找不到 ID 为1的assets资源 .请判断图像源或打包器

React Native TextInput 在android上打开时会自动关闭

React Native Navigation const { navigate } = this.props.navigation;

应用程序主体尚未注册

调用 ES6 方法时绑定上下文.如何从称为回调的方法中访问对象?

react-native 中的layout-only view removal优化是什么?

React Native Card Carousel 视图?

在 React Native 中计算两个 lat+lng 坐标之间的距离?

没有找到 `React-fishhook` 的 podspec

无法解析模块 react/lib/ReactUpdates

在 Docker 中使用 Fastlane 构建 iOS 应用

React Native Negative shadowOffset 创建顶部阴影

如何在 React Native 中使用 index.js 而不是 (index.ios.js, index.android.js) 进行跨平台应用程序?

如何在自定义组件上使用 onPress?

React Native Navigation 组件路由问题

react-native图像预取

React Native font outline / textShadow

使用行数react-native文本组件