2

For Web applications hosted on Firebase, I want to verify new users by emailing them a verification link. I went through the documentation, Create custom email action handlers, and configured my custom domain and have password authentication working fine.

So, how do I trigger a password verification? How do I get the oobCode and apiKey arguments? I'm registering a new user fine and nothing happens on my auth listener page?

var getArg = getArg();
var mode = getArg['mode'];
var oobCode = getArg['oobCode'];
var apiKey = getArg['apiKey'];

console.log(mode, oobCode, apiKey);

switch (mode) {
    case 'resetPassword':
        console.log('Password Request Fired');
        break;
    case 'recoverEmail':
        console.log('Recover Email Fired');
        break;
    case 'verifyEmail':
        console.log('Verify Email Fired');
        break;
}

//Thanks Geoffrey Crofte
function getArg(param) {
    var vars = {};
    window.location.href.replace(location.hash, '').replace(
        /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
        function(m, key, value) { // callback
            vars[key] = value !== undefined ? value : '';
        }
    );

    if (param) {
        return vars[param] ? vars[param] : null;
    }
    return vars;
}
7
  • See here, it might shed some light on what you could do: stackoverflow.com/documentation/proposed/changes/35793 Commented Jul 23, 2016 at 22:59
  • @Rexford: please provide the necessary information as an answer. Otherwise we'll just get unanswered questions with comments linking to the docs. Commented Jul 23, 2016 at 23:16
  • @FrankvanPuffelen Well noted. Perhaps this could or should be marked as duplicate, because I've seen a couple of email verification related questions (this: stackoverflow.com/questions/17723195/… and this stackoverflow.com/questions/38142317/… and added the answer in the above link. Commented Jul 23, 2016 at 23:21
  • Truth is a vanilla JS (no angular or jQuery) snippet would be nice. If nobody post an answer I'll come back and post one when I get it working. Commented Jul 23, 2016 at 23:35
  • @RonRoyston In my example, I am not using AngularJS entirely. See that I do firebase.auth().applyActionCode(...)? That is vanilla js, because there aren't AngularJS wrappers for some, like the .applyActionCode() yet, at the moment. Will love to see it in vanilla js entirely. Commented Jul 23, 2016 at 23:38

1 Answer 1

1

firebase.auth().currentUser.sendEmailVerification() sends the mode, oobCode, and apiKey variables to the signed in users email address. Until verified, the signed in user can be identified as unverified by reading the currentUser.emailVerified property. User opens email and clicks verification link which invokes HTTP session to your auth listener page with those variables present as arguments in the URL.

Using the getArg() method in my original post (or your own) parses the arguments out of the browsers window.location (current web address/URL) into variables in your auth listener page's JavaScript.

  1. build out your auth listener page (mostly paste from docs)
  2. send signed in user an email

    firebase.auth().currentUser.sendEmailVerification()
    //checks if signed in user is verified, if not tell them to check email
    firebase.auth().currentUser.emailVerified; //false now so handle user experience appropriately until verified
    

Official Web Methods Reference Index is useful. Some other relevant methods (all thenable) are shown below:

//updates email of signed in user
-> firebase.auth().currentUser.updateEmail(newEmail)

//updates password of signed in user
-> firebase.auth().currentUser.updatePassword(newPassword)
-> firebase.auth().sendPasswordResetEmail(email)

//deletes auth account of signed in user
-> firebase.auth().currentUser.delete()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for posting this. There is not enough documentation on this topic. I'm having my own email verification problem. If you have any advice, please let me know. It would be very appreciated. stackoverflow.com/questions/51178015/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.