-2

我正在使用Firebase Web SDK並知道方法來檢查集合中的子項是否存在。但是我無法找到一個簡明的例子檢查用戶的存在,但不嘗試簽下他/了她。如何查找用戶是否存在於Firebase中?

export class Email extends Component { 
    constructor (props) { 
    super(props) 
    this.state = { email: '' } 
    } 

    checkEmail() { 
    const { email } = this.state 
    FirebaseApp.auth() 
    .createUserWithEmailAndPassword(email, uuid.v4()) 
    .then((User) => Actions.Password({ User })) 
    .catch((error) => { 
     // Handle Errors here. 
     console.log('firebase', {error}) 
     this.setState({error}) 
     // ... 
    }) 
    // Actions.password() 
    } 

    render() { 
    return (
     <View style={{ ...styles.onboarding, backgroundColor: 'purple' }}> 
     <View style={{ borderBottomWidth: 3, borderColor: 'black', padding: 10 }}> 
      <TextInput ref='email' 
      style={styles.input} 
      keyboardType='email-address' 
      placeholder='Your email' 
      value={this.state.email} 
      onChangeText={(email) => this.setState({email: email.toLowerCase()})} /> 
     </View> 
     {!this.state.error ? null 
      : <Text> 
      {this.state.error.message} 
      </Text> 
     } 
     <TouchableOpacity onPress={() => this.checkEmail()} style={{ ...styles.button, margin: 20, borderColor: 'black' }}> 
      <Text style={styles.buttonText}>Next</Text> 
     </TouchableOpacity> 
     </View> 
    ) 
    } 
} 

你有一段代碼,我們可以重用?

+0

你有你想查詢的用戶的用戶ID嗎? –

+0

不,我想在創建用戶之前檢查存在 – jsdario

+0

您的數據庫中的用戶標識是否由OAuth自動生成,還是由用戶選擇/自定義? –

回答

0

目前,由於它符合我的應用程序安全策略和設置,我創建了一個由id精確索引的電子郵件收藏集。

firebase.ref(`emails/${user.email}`).set(true) 
相關問題