【问题标题】:Firebase email verification WITHOUT creating an account in React NativeFirebase 电子邮件验证,无需在 React Native 中创建帐户
【发布时间】:2020-12-26 22:49:27
【问题描述】:

我对 Firebase 中的电子邮件验证有疑问。我找到了here的问题的解决方案。但是当我将代码转换为原生反应时。它没有按预期工作。

我的功能

const onSignIn = () => {

auth()
  .signInAnonymously()
  .then(() => {
    console.log('User signed in anonymously');

    auth()
      .onAuthStateChanged((user) => {
        user.updateEmail('jasurkurbanov96@gmail.com');
        user.sendEmailVerification();
      })
      .catch(function (error) {
        console.log('error', error);
      });
  })
  .catch((error) => {
    if (error.code === 'auth/operation-not-allowed') {
      console.log('Enable anonymous in your firebase console.');
    }
    console.error(error);
  });

navigation.push('SignUpConfirm');

};

基本上我想要实现的是。当用户进入应用程序时,我只需要显示电子邮件输入。一旦用户 输入电子邮件地址,Firebase 应向提供的电子邮件用户发送确认码。

【问题讨论】:

  • 错误是什么?这两个调用都是异步的,所以如果你不等待 updateEmail 完成,sendEmailVerification 会抛出一个错误。
  • 1) 你怎么知道它是异步的? 2) 我的电子邮件正在更新,但 sendEmailVerification 不起作用。 3)我会看到错误日志而不是

标签: javascript reactjs firebase react-native firebase-authentication


【解决方案1】:

您应该阅读文档https://rnfirebase.io/reference/auth/user#updateEmail,下面的代码应该可以工作。如果不打印您遇到的错误。

登录屏幕

const onSignIn = () => {

auth()
  .signInAnonymously()
  .then(() => {
    console.log('User signed in anonymously');
  .catch((error) => {
    if (error.code === 'auth/operation-not-allowed') {
      console.log('Enable anonymous in your firebase console.');
    }
    console.error(error);
  });

navigation.push('SignUpConfirm');

};

SignUpConfirm 屏幕

useEffect(() => {
    auth().onAuthStateChanged((userIs) =>
      userIs
        .updateEmail('jasurkurbanov96@gmail.com')
        .then(() =>
          userIs
            .sendEmailVerification()
            .then(() => console.log('email verificiation sent')),
        )
        .catch((err) => console.log('This is', err)),
    );
  }, []);

【讨论】:

    猜你喜欢
    • 2017-02-23
    • 2019-02-13
    • 1970-01-01
    • 2021-10-10
    • 2021-08-17
    • 1970-01-01
    • 2020-02-03
    • 2020-09-08
    • 2022-12-04
    相关资源
    最近更新 更多