Skip to content

Simple Firebase Email Verification in 3.0 SDK

Posted in Javascript

In any authentication system, to verify the email addresses coming through your system are legit, very often, developers will want to send a verification email to the email on file, then a confirmation link will be used to verify the email address is viable.

Updated Aug 21, 2016. 13:48: Added a repository to help you get started easily, thanks to a comment. Here we go: https://github.com/seanmavley/Firebase-Email-Verification

If you’re familiar with Firebase, you’ve probably come to love how authentication is made seamless and easy to implement with rich APIs.

Well, one of the features that were missing happened to be the option of sending verification email after local account signups.

You can customize your email templates that are sent out in Firebase relation to email verification and more. See here: https://console.firebase.google.com/project/your-project-name/authentication/emails

If a user signs up with a social authentication, either from Facebook or Google, there’s a high chance the email is a legit  one you’re putting onto the file. However, a user signing up using your local account system, you better verify.

In Firebase 3.0 SDK, email verification is baked in and pretty beautiful to implement.

Sending Verifications

A function to send a verification email. currentAuth is a controller like this, from my ui-router:

Then you just inject into your controller, wherever you want it!

After sending the verification, you’ll have to accept the link sent and chew it to verify your user email.

So, it can be done this way:

We consume the params using the ?mode&oobCode . If you’re wondering what the oobCode is, check out the docs to learn more.

You could use url: '/verify-email/:mode/:oobCodeequally, and it’ll function accordingly, as long as you intercept the params the ui-router way.

We did mention the emailVerifyController, so let’s bring it into perspective:

Why are we using firebase.auth? Well, AngularFire hasn’t come around to implementing or wrapping around all the new cool kid’s functions and features available with the 3.0 SDK of Firebase. However, dropping down to vanilla Javascript Firebase still works, besides, why not!

You may decide to checkCode as in check the oobCodeif you want to, before processing it. It’s up to you.

Hope you enjoyed this short one. Will see you in the next one.