I have an Android app that already has Email and Password authentication using Firebase. For the user's ease, I have now added Google Sign-In in the project as well.
The problem is that when I log in using email, then the app creates some data on Realtime Database under key as per UID (Unique User ID - Acquired By Firebase Auth) of the user. This data is generally created at the time of the user's registration. But while, when users use the Google sign-in feature, they are authenticated through another activity hosted by google play services. I am unable to add this data.
So, the question arises that what should I do now to check if the user just did the login with a Google account or not. Also, if the user does google login for the first time, it will create the new data at the real-time database, else it will retrieve the data.
Please help me as I am stuck.
In javascript, the following method firebase.auth().signInWithCredential
returns firebase.auth.UserCredential
which has a property additionalUserInfo
.
additionalUserInfo
has a boolean property called isNewUser
.
You can place a simple check on isNewUser
to check if the user is signing in for the first time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With