Is there any way to do email confirmation for Firebase user creation and/or password reset?

deitch picture deitch · Jul 18, 2013 · Viewed 28.8k times · Source

Question says it all. In Firebase, how do I confirm email when a user creates an account, or, for that matter, do password reset via email.

I could ask more broadly: is there any way to send emails out from Firebase? E.g. notifications, etc. This isn't the kind of thing you would usually do client-side.

Answer

amcdrmtt picture amcdrmtt · Feb 5, 2014

Update

Note that this was never a very secure way of handling email verification, and since Firebase now supports email verification, it should probably be used instead.

Original answer

I solved the email verification using the password reset feature.

On account creation I give the user a temporary (randomly generated) password. I then trigger a password reset which will send an email to the user with a link. The link will allow the user to set a new password.

To generate a random password you can use code similar to this:

function () {
  var possibleChars = ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?_-'];
  var password = '';
  for(var i = 0; i < 16; i += 1) {
    password += possibleChars[Math.floor(Math.random() * possibleChars.length)];
  }
  return password;
}

Note that this is happening on the client, so a malicious user could tamper with your logic.