Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Firebase Reset Password Email After Account Created On Server/Admin

I'm creating a website where businesses can offer my service to their clients/users for free. For a business to add a user (under their business account), the business logs in and inputs one of their clients/users email. I then send the client/user email to firebase functions and programmatically create an account.

I would like to send this new user a email saying something like 'Account Created: Reset Password' etc., I could do this using sendPasswordResetEmail on the browser, but this function is not available on Firebase functions/admin.

The best option I can think of it to randomly generate a password for each new user (ie - 'ef53gs'), and share the new password in a Welcome Email, but I think it would be a better experience if the Welcome Email included a link to (re)set their password.

Any idea's how to make something like sendPasswordResetEmail work for firebase functions?

like image 509
Will Avatar asked Jun 22 '18 01:06

Will


People also ask

How do I reset my Firebase authentication password?

To send a password reset email to user, on the Users page, hover over the user and click ... > Reset password. The user will receive an email with instructions on how to reset their password.

How can I get Firebase password of current user?

To access these parameters, navigate to the 'Users' tab of the 'Authentication' section in the Firebase Console and select 'Password Hash Parameters' from the drop down in the upper-right hand corner of the users table.


3 Answers

We ran into the same issue since the firebase-admin does not have a sendPasswordResetEmail() like the firebase SDK does. We ended up just using the firebase client SDK on the server as well alongside the firebase-admin. Works fine.

like image 189
jpunk11 Avatar answered Oct 11 '22 11:10

jpunk11


I think a rather better way to do that is to actually use the REST API to reset the users passwords from the admin without adding a client library to the admin site.

curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/getOobConfirmationCode?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"requestType":"PASSWORD_RESET","email":"[[email protected]]"}'

[API KEY] can be retrieved from Project Settings > add an app >> click web and you will get the configuration with a JSON, within the JSON there is an APIKey that is the one that you need to use.

like image 27
N Jay Avatar answered Oct 11 '22 11:10

N Jay


The admin sdk has a generatePasswordResetLink which will create the link for you but it's on you then to handle sending the email which you can do using any service you'd like such as mailgun or mandrill. This also gives you more control over the email template.

like image 22
askilondz Avatar answered Oct 11 '22 10:10

askilondz