gpt4 book ai didi

javascript - Firebase 检测用户是否存在

转载 作者:数据小太阳 更新时间:2023-10-29 05:43:56 25 4
gpt4 key购买 nike

如何通过 React Native 检查 Signup 按钮中的 Firebase 身份验证中是否存在用户?

这是我的登录页面代码:

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>
)
}
}

最佳答案

您需要使用 fetchSignInMethodsForEmail API。它接受一封电子邮件并返回一个 promise ,如果它已经注册,该 promise 将解析为链接到该电子邮件的提供商列表: https://firebase.google.com/docs/reference/js/firebase.auth.Auth.html#fetchsigninmethodsforemail

关于javascript - Firebase 检测用户是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44615808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com