why is the redirect not working after verification?

Since EmailLink is rendered in Switch by a Route component it receives route props. Use the passed history object to handle the redirect using history.replace().

Side note, you should not issue asynchronous calls and side effects from the “render”, use an useEffect hook to handle this when the component mounts.

const EmailLink = ({ history, match }) => {

  useEffect(() => {
    const testEmailAuth = () => {
      if (firebase.auth().isSignInWithEmailLink(match.url)) {
        if (!email) {
          return null;
        }
        firebase
          .auth()
          .signInWithEmailLink(email, match.url)
          .then(function(result) {
            history.replace('/'); // <-- replace === redirect
          })
          .catch(function(error) {
            console.log('error ' + error);
          });
      }
    };

    testEmailAuth();
  }, []);

  return (
    <div className="EmailLink" />
  );
};

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top