0

in my App, I use firebase database and the auth-service for new registrations.

The new user will be added to the authentification users-list, but there is still one missing part. The new user won't be added to database collection 'users'.

Is there any service in firebase to add new users to the database if they have the status emailVerified: true or do I have to do this on the client side? Thank you for your hints!

SendVerificationMail() {
  // Email verification when new user register
  return this.ngFireAuth.auth.currentUser.sendEmailVerification() .then(()=> {
    this.router.navigate(['verify-email']);
  })
}

SetUserData(user) {
  const userRef: AngularFirestoreDocument<any>=this.afStore.doc(`users/$ {
    user.uid
  }
  `);
  const userData: User= {
    uid: user.uid, email: user.email, displayName: user.displayName, photoURL: user.photoURL, emailVerified: user.emailVerified
  }
  return userRef.set(userData, {
    merge: true
  }
  )
}
Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302
mm1975
  • 1,338
  • 4
  • 23
  • 42
  • Does this answer your question? [Cloud Functions for Firebase - action on email verified](https://stackoverflow.com/questions/43503377/cloud-functions-for-firebase-action-on-email-verified) – cjd82187 Jul 23 '20 at 15:46
  • thx! but is there any other possibility? Because it is a paid service... – mm1975 Jul 23 '20 at 16:18

1 Answers1

1

If you are asking if there is a way to make a change to the database as soon as the user's email becomes verified, then no, there is no hook or trigger for that. You will have to arrange for some code to check if the flag is set in Firebase Auth, then update the database as needed.

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302