I have created an app that has multiple sign-in options such as email and password or with google account.
Every time a user is signing in, I save some data about it such as account creating data, nickname and so on.
I store it in my Firebase database in the following path:
Users (collection) -> auth.getuid (document with unique id) -> UserData (collection) ->some fields
So when I sign in using email and password and I use to authenticate, I can get a unique id by using auth.getid. In that way I make sure there won't be 2 same documents for different users.
Now, if I use google sign in by using the following:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestSignInCode){
GoogleSignInResult googleSignInResult = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (googleSignInResult.isSuccess()){
GoogleSignInAccount googleSignInAccount = googleSignInResult.getSignInAccount();
FirebaseUserAuth(googleSignInAccount);
FirebaseFirestore db = FirebaseFirestore.getInstance();
Map<String, Object> user = new HashMap<>();
user.put("username", googleSignInAccount.getEmail());
user.put("email",googleSignInAccount.getEmail());
user.put("dateCreated", FieldValue.serverTimestamp());
db.collection( "Users" ).document(auth.getUid()).collection( "UserData" ).add( user );
Intent intent = new Intent( SignInActivity.this, DiscoverActivity.class );
startActivity(intent);
finish();
}
}
}
Is there anything equivalent to auth.getuid when using google sign-in so I could create a unique document for that user?
Or even better, can I still somehow use auth.getID? because if in all of my code when I used email + password sign-in I could query by using auth.getuid, now I won't be able and will need to create a separate query based on some google.id?
Thank you