Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase auth onUpdate cloud function for when a user updates their email

I need to run a Firebase function whenever my user updates their email address, except auth only has onCreate and onDelete. How can I react to email updates?

like image 489
Michael Ozeryansky Avatar asked Dec 21 '17 22:12

Michael Ozeryansky


People also ask

Can you change email in Firebase Auth?

FOR FIREBASE V9 (modular) USERS: if any others trying this code please don't forget to re-login (firebase needs recent login token) firebase user. then only firebase will allow to change email address.

What does Firebase auth () CurrentUser return?

If a user isn't signed in, CurrentUser returns null. Note: CurrentUser might also return null because the auth object has not finished initializing.

How do I use Firebase authentication email?

If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.

When should I use Firebase cloud function?

You should use Cloud Functions for Firebase if you're a developer building a mobile app or mobile web app. Firebase gives mobile developers access to a complete range of fully managed mobile-centric services including analytics, authentication and Realtime Database.


1 Answers

It's not possible today to directly react to an email address changing in Firebase Authentication. If you'd like to see that as a feature, please file a feature request.

You can react to it indirectly by having your app listen to authentication events (Android), take the User object delivered to your listener, and write the user's email address to a RealtimeDatabase location (or Firestore document) for that user's UID. Then, you can have a database trigger that tracks the location of your users in the database, and react to the change there.

like image 153
Doug Stevenson Avatar answered Nov 03 '22 23:11

Doug Stevenson