繁体   English   中英

Firebase 电子邮件验证,无需在 React Native 中创建帐户

[英]Firebase email verification WITHOUT creating an account in React Native

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

我的功能

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 应向提供的电子邮件用户发送确认代码。

您应该阅读文档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');

};

注册确认画面

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)),
    );
  }, []);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM