User.emailVerified does not change after clicking on the firebase email confirmation link

After studying the sending, email verification is possible in the latest version of firebase , although there are no documents, I wanted to check it for myself.

Using the snippet below:

  Auth.$onAuthStateChanged(function(firebaseUser) {
    if (firebaseUser) {
      console.log(firebaseUser);
      if (firebaseUser.emailVerified) {
        // console.log(firebaseUser.emailVerified); 
        toastr.success('Email verified');
      } else {
        toastr.info('Do verify email');
      }
    }
  })

console.log(firebaseUser.emailVerified) always returns false, although a send verification was initiated, the received email message was pressed.

Immediately after logging in to the system, I check if the user is checked, if not, send an email:

Auth.$signInWithEmailAndPassword(email, password)
  .then(function(firebaseUser) {
    if (!firebaseUser.emailVerified) {
      firebaseUser.sendEmailVerification();
      console.log('Email verification sent');
    }
    $state.go('home');
  })

In my https://console.firebase.google.com/project/my-app-name/authentication/emailseverything is by default, with a confirmation link, like:

Follow this link to verify your email address. https://my-app-name.firebaseapp.com/__/auth/handler?mode=<action>&oobCode=<code>

, , , , user.emailVerified true.

, , ?

+7
4

@Tope, firebaseUser.reload(), firebaseUser.

+4

:

auth.currentUser.emailVerified

auth.currentUser.sendEmailVerification()

auth.currentUser.emailVerified

True

3 4: , emailVerified .

, : Firebase

+2

, :

angular.module('theApp')

.controller('emailVerifyController', ['$scope', '$stateParams', 'currentAuth', 'DatabaseRef',
  function($scope, $stateParams, currentAuth, DatabaseRef) {
    // where currentAuth and DatabaseRef is what they sound like
    $scope.doVerify = function() {
      firebase.auth()
        .applyActionCode($stateParams.oobCode)
        .then(function(data) {

          // change emailVerified for logged in User
          // you can update a DatabaseRef endpoint in here
          // whatever!

          toastr.success('Verification happened', 'Success!');
        })
        .catch(function(error) {
          $scope.error = error.message;
          toastr.error(error.message, error.reason, { timeOut: 0 });
        })
    };
  }
])

- :

<a ng-click="doVerify()" class="button large">Verify my Account</a>

, applyActionCode AngularFire, Javascript SDK AngularJS, , !

Firebase:
https://blog.khophi.co/email-verification-firebase-3-0-sdk/

+2

, , user.reload() onAuthStateChanged onIdTokenChanged.

, firebase emailVerifed, onIdTokenChanged Id .

:

export function* register_user(action) {
  try {
    //Call api which registers user and sets email verified to true
    let register_result = yield call(Register_API.create_registration, action.data)

    if (register_result && register_result.status >= 200 && register_result.status < 300) {
      let user = firebase.auth().currentUser
      //Force user to reload so we can trigger the onIdTokenChanged listener
      return user.reload()
    }

  } catch (e) {
    console.error(e)
  }
}


firebase.auth().onIdTokenChanged(function (user) {
      if (user && user.uid) {
        if (user.emailVerified) {
         //Stuff you want to do
        }
      }
    })
0

All Articles