Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know that a user clicked on the verification link?

Here's the code I'm using to send a verification email (taken from the official docs)

var user = firebase.auth().currentUser;

user.sendEmailVerification().then(function() {
  // Email sent.
}).catch(function(error) {
  // An error happened.
});

User object has emailVerified property. It doesn't change when user clicks the link in the mail. It only updates on re-login. Is there a way for an app to know that a user sucessfully verified their address?

like image 619
manidos Avatar asked Oct 25 '17 16:10

manidos


2 Answers

firebaser here

There is no client-side callback that triggers when the user clicks the verification link.

We've seen a feature request to trigger Cloud Functions when a user verifies their email address, but no updates on whether/when that will come. (Also see: Cloud Functions for Firebase - action on email verified)

The best I can think of now is to call User.reload() occasionally to get the updated properties.

like image 183
Frank van Puffelen Avatar answered Oct 18 '22 13:10

Frank van Puffelen


You can add a continueUrl when sending an email verification to redirect back to your app: https://firebase.google.com/docs/auth/web/passing-state-in-email-actions

var actionCodeSettings = {
  url: 'https://www.example.com/?email=' + 
       firebase.auth().currentUser.email
};
firebase.auth().currentUser.sendEmailVerification(actionCodeSettings)
  .then(function() {
    // Verification email sent.
  });

This will show a continue button after verification. You can use it to go back to the app or to some page where you can notify the original page via real time database of the verification.

like image 23
bojeil Avatar answered Oct 18 '22 14:10

bojeil