android


Sign in with Facebook if account already linked with google during initial signup in Firebase Android


I am trying to sign in with facebook in the reinstallation of android app. Initially I signed up using Google and successfully linked it with firebase.
But when I try to do with facebook it gives a
FirebaseAuthUserCollisionException
I read in Firebsae documentation here that you can do so by
FirebaseUser prevUser = currentUser;
currentUser = auth.signInWithCredential(credential).await().getUser();
// Merge prevUser and currentUser accounts and data
// ...
but here await() method no longer exists. Also after searching a bit I found out this solution
Tasks.await(mAuth.signInWithCredential(credential)).getUser();
But this also gives error in getting the current user which is already linked. What can I do to solve this?
There is no need in .await() method to get firebase user.
Use FirebaseAuth.AuthStateListenerinstead.
So you implement firebase sign in with something like this:
FirebaseAuth.getInstance()signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "login success");
} else {
Log.d(TAG, "login error");
}
}
});
And implement AuthStateListener which is trigerred every time user state is changed:
private FirebaseAuth.AuthStateListener authStateListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initAuthStateListener();
}
private void initAuthStateListener() {
authStateListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user == null) {
//user is not logged in
} else {
//user is logged in
//logic to finish the activity and proceed to the app can be put here
}
}
};
}
#Override
protected void onStart() {
super.onStart();
FirebaseAuth.getInstance().addAuthStateListener(authStateListener);
}
#Override
protected void onStop() {
super.onStop();
FirebaseAuth.getInstance().removeAuthStateListener(authStateListener);
}
Note: onAuthStateChanged is trigerred once when authStateListener is added to firebase auth instance.
Also make sure Prevent creation of multiple accounts with the same email address parameter is set on firebase console (Authentication >> SIGN-IN METHOD >> Advanced >> One account per email address (Change) ).

Related Links

Charles Proxy + Android HTTPS
ScaleGestureDetector and GestureDetector in same view
Is there a performance impact on changing color of vector drawables programmatically?
Android web view does not load specific url
Attempt to invoke virtual method 'void android.widget.CompoundButton.setOnCheckedChangeListener on a null object reference on TabLayout [duplicate]
Retrieve all data from mysql database and display in listview android
Native Activity, GLES2.0: Uploading pixel array to screen
Get runtime Permissions in FirebaseInstanceIDService
android google maps get place details and send them to another activity
How to update an array of objects in Firebase?
Getting Raspberry pi events from android/iOS app
Android AccountManager adds account, but dissapears after
react native external packages will take more memory in project
Check fragment is currently visible or not in android?
Single activity vs multiple
How to pass install referrer string to my App

Categories

HOME
twitter-bootstrap-3
gdb
alexa-skills-kit
3d
nested-if
jax-ws
modal-dialog
rcloud
spin
owin
why3
emoji
filechannel
automatic-ref-counting
modbus-tcp
internationalization
job-scheduling
mathprog
feathersjs
shortest-path
sar
named-entity-recognition
ios10.2
outliers
ms-access-2003
vex
alm
calculation
autodesk-designautomation
fossil
openalpr
android-augmented-reality
z-notation
ods
demo
cin
kill
skylink
android-ibeacon
install.packages
phpdbg
httrack
ovf
qtranslate
static-cast
wpas
truezip
backbone-collections
java-websocket
change-tracking
taocp
simplepie
pytables
myspace
tinkerpop3
xdoclet
respondcms
spreadjs
lz77
jbase
dynamics-nav-2016
boomerang
java-money
r-package
rate-limiting
binomial-theorem
text-search
coda
.bash-profile
mod-proxy
graphics2d
aspectj-maven-plugin
ejb-2.x
beatsmusic
linkedin-jsapi
create.js
lambda-architecture
cuba
live555
memset
buffering
extjs2
multiautocompletetextview
gtm-oauth2
mongohq
tree-balancing
subgraph
garbage
jsr286
procedures
user-tracking
promotion-code
google-floodlight
uideviceorientation
facebook-iframe
drupal-fivestar
ajax-polling
tabpanel
echo3
strtod
skype4java
mathematical-notation
application-planning
httpcookie

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App