Reactjs 创建一个中间步骤,使用firebase、react native验证电子邮件地址

Reactjs 创建一个中间步骤,使用firebase、react native验证电子邮件地址,reactjs,firebase,react-native,firebase-authentication,Reactjs,Firebase,React Native,Firebase Authentication,我正在尝试使用react native和firebase验证我的电子邮件地址。目前,我有一个注册页面,在输入所有凭证后,它会向电子邮件发送一个验证链接,我将直接进入一个新屏幕。没有办法验证我的电子邮件。首先,我试图通过单击电子邮件链接验证我的电子邮件,然后,我可以导航到新屏幕。我正在尝试创建一个中间步骤来验证我的电子邮件地址,目前无法验证我的电子邮件链接 这是我的尝试 register: async (email, password) => { try {

我正在尝试使用react native和firebase验证我的电子邮件地址。目前,我有一个注册页面,在输入所有凭证后,它会向电子邮件发送一个验证链接,我将直接进入一个新屏幕。没有办法验证我的电子邮件。首先,我试图通过单击电子邮件链接验证我的电子邮件,然后,我可以导航到新屏幕。我正在尝试创建一个中间步骤来验证我的电子邮件地址,目前无法验证我的电子邮件链接

这是我的尝试

register: async (email, password) => {
          try {
            const userCredential = await auth().createUserWithEmailAndPassword(
              email,
              password,
          );
         await userCredential.user.sendEmailVerification();
       } catch (e) {
      console.error(e);
    }
},
这是我尝试重定向到一个新屏幕

import React, {useContext, useState, useEffect} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import auth from '@react-native-firebase/auth';
import {AuthContext} from './AuthProvider';

import AuthStack from './AuthStack';
import AppStack from './AppStack';

const Routes = () => {
    // getting the created user
  const {user, setUser} = useContext(AuthContext);
 
  // subscribe to the users current authentication state, and receive an event whenever that state changes.
  const onAuthStateChanged = user => {
    setUser(user);
  };

  useEffect(() => {
    const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
    return subscriber; // unsubscribe on unmount
  }, []);


  return (
    <NavigationContainer>
      {user ? <AppStack /> : <AuthStack />}
    </NavigationContainer>
  );
};

export default Routes;

import React,{useContext,useState,useffect}来自“React”;
从'@react-navigation/native'导入{NavigationContainer};
从'@react native firebase/auth'导入身份验证;
从“/AuthProvider”导入{AuthContext};
从“/AuthStack”导入AuthStack;
从“./AppStack”导入AppStack;
常数路由=()=>{
//获取创建的用户
const{user,setUser}=useContext(AuthContext);
//订阅用户当前的身份验证状态,并在该状态更改时接收事件。
const onAuthStateChanged=用户=>{
setUser(用户);
};
useffect(()=>{
const subscriber=auth().onAuthStateChanged(onAuthStateChanged);
返回订阅服务器;//卸载时取消订阅
}, []);
返回(
{用户?:}
);
};
导出默认路径;

只有在验证电子邮件后才能设置用户,如下所示。如果用户电子邮件地址未经验证,则添加一个中间屏幕

const [user, setUser] = useState(false);
const [emailVerified, setEmailVerified] = useState(true);

firebase.auth().onAuthStateChanged(function (user) {
    if (user) {
        if(user.emailVerified){
            setUser(true);  setEmailVerified(true);

        }
        else{
            setEmailVerified(false);
        }
    }
});
然后使用条件渲染,如下所示:

{user && <AppStack />}
{!user && <AuthStack />}
{!emailVerified && <EmailPendingVerifiedScreen />}
{user&&}
{!用户&}
{!emailVerified&}
您看过吗?