How to use multi Auth - firebase?

∥☆過路亽.° 提交于 2019-12-09 03:51:23

问题


I have a register screen that contains "username, email, phone number, Password" and in this case, I use Phone Number Authentication to verify the number so after user verify his number I save his data into firebase DB,

so after that, I navigate hem to login screen! that should contain Email, Password "he registered by them before"

So I don't just compare if his data exist in DB or not, So it should be used Email/Password Firebase Auth,

But I think it's will take a lot of hits to my Bill or something,

so what you think to achieve these cases because I'm forced to register by Email For Reset Password later?

here is my register Code

 signUp = async () => {
    const {phoneNumber} = this.state;
    this.setState({message: 'code was sent'});
    const phoneWithAreaCode = phoneNumber.replace(/^0+/, '+972');
    console.log(phoneWithAreaCode);
    auth()
      .signInWithPhoneNumber(phoneWithAreaCode, true)
      .then(confirmResult => {
        console.log('confirmResult', confirmResult);
        this.setState({confirmResult, message: 'code was sent'});
        // this.createUserDatabase();
      })
      .then(() => {
        this.props.navigation.navigate('Confirmation', {
          message: this.state.message,
          confirmResult: this.state.confirmResult,
          createUser: uid => this.createUserDatabase(uid),
          phoneWithAreaCode: phoneWithAreaCode,
          signInPhoneNumber: phone => auth().signInWithPhoneNumber(phone),
        });
      });
  };

  createUserDatabase = uid => {
    const {userName, phoneNumber, email} = this.state;
    // const uid = auth().currentUser.uid;

    const data = {
      uid,
      name: userName,
      email: email,
      phoneNumber: phoneNumber,
    };

    database()
      .ref(`users/${uid}`)
      .set(data)
      .then(() => {
        console.log('New poll data sent!');
      })
      .catch(error => console.log('Error when creating new poll.', error));
  };

来源:https://stackoverflow.com/questions/59033989/how-to-use-multi-auth-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!