How to handle email verification flow when users sign up with Google OAuth in a way that avoids the verify account page? Answered

Post author
Heather B

Hi everyone, I am finding that when users sign up with Google, rather than entering email and password, they are automatically verified. This is a problem because they are sent to the verify your account page - without having actively verified their account and there isnt an automatic redirect. Any help would be appreciated thank you.

Comments

6 comments

  • Comment author
    Raquel Lopez
    Hi Heather,
     
    To solve that little issue you can create a script in the verified account page, to check if the user is verified to automatically redirect them. That would act like a wall that so any verified user won't ever be able to access that page again.
     
    Try paste this script before the </body> tag for your verified page
    const currentUser = JSON.parse(localStorage.getItem("_ms-mem")); 

    if (currentUser) {
    if(currentUser.verified) {
    location.href = "/dashboard"; // adjust the url to your choice
    }
    }
    The "verify" boolean acts to check if the email exists. When people use Google to login its automatically implied that the user's Google email exists because if not, they won't be able to login using Google 🙂
     
    0
  • Comment author
    Heather B

    That makes sense. Is there a way for them to not be taken to the verification screen? They should be taken to the sign up redirect rather than the verification required redirect no?

    0
  • Comment author
    Raquel Lopez

    There's no way to set a custom verification in memberstack dashboard, for that specific rule. So my solution is since all your newly registred users are already going to the verified page, in there you add an extra check that if they are verified they will automatically redirect where you said them to be. They probably won't even notice they first got to the verified page, they redirection would be quick

    Many people use a "success page strategy" where the success page is a blank page with a bunch of logic on the background to redirect the user depending on different conditions.

    In this case, since it's a small condition, I'm only suggesting you do the redirect logic in the same page. The user should get redirected while the page is still loading

    0
  • Comment author
    Heather B

    Please you have a code snippet I could use for the redirect on the verify your account page? I tried this but it didnt work:

    <script>
    document.addEventListener("DOMContentLoaded", function() {
    MemberStack.onReady.then(function(member) {
    if (member.loggedIn) {
    var isVerified = member["verifiedStatus"];
    if (isVerified) {
    window.location.href = "/member/set-up";
    }
    } else {
    console.log("User is not logged in.");
    }
    });
    });
    </script>
    0
  • Comment author
    Raquel Lopez

    Did you tried the one that I shared earlier? 😅

    const currentUser = JSON.parse(localStorage.getItem("_ms-mem"));

    if (currentUser) {
    if(currentUser.verified) {
    location.href = "/dashboard"; // adjust the url to your choice
    }
    }

    MemberStack.onReady is from version 1.0, it won't work if you're using v2

    I prefer to get the data from localStorage instead of using getCurrentMember method because that way I don't have to wait a few milliseconds to get the response from memberstack server.

    The less requests there are on the page the better performance would get 🙂 like less loading times

    0
  • Comment author
    Heather B

    Oh it was not there before. I used it and it worked now thanks 🙂

    0

Please sign in to leave a comment.