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

How to pass JSONArray From Activity to Html Script?
Why this image-switching code has memory leak?
error in integration of mupdf library
Does whatsapp use c2dm aka GCM on android?
android transition
ImageView resizing with out blur
Encryption of pdf using itext Library
intent to open browser not working on tabhost
Is there a way to detect headphones natively? [duplicate]
Difference between build.xml and project_name.xml
Android best way to communicate from an Activity to a Service / Engine
Javadoc for ORMlite attached, but not found by Eclipse
How Mobile device Simulation works?
AbstractHttpClient.class Source not found
How to create a header for urllib2, to make it look like it is cell phone. Python
Using both list navigation and tabs with ActionBarSherlock?

Categories

HOME
ggplot2
google-spreadsheet
static
pascal
camera
graphics
gembox-spreadsheet
polling
nfs
joomla3.0
rcloud
okhttp
plist
redis-sentinel
jxl
stellar.js
internationalization
azure-iot-hub
symfony-2.8
powershell-v5.0
vuejs
soci
sse
symbols
rubymotion
flask-sqlalchemy
displaytag
jboss6.x
windows-server-2003
interbase
fable-f#
iis-express
jbutton
git-squash
android-sugarorm
joomla2.5
html-encode
sessionstorage
loading
css-position
news
odoo-website
wmp
apollostack
dapper-simplecrud
mongotemplate
page-replacement
sundials
css-transforms
mathcad
docpad
preprocessor
vulcanize
jboss-tools
xdoclet
respondcms
phpwebsocket
libav
nullable
np-spring
dynatree
tfs-workitem
file-move
lazybones
dock
pax-exam
atoi
dronekit-android
dnssec
grouping-sets
uncaught-typeerror
iiop
iso-prolog
universal-image-loader
kissfft
mintty
jjaql
rfc5322
embedded-fonts
scrypt
code-duplication
cffile
poker
time.h
actiondispatch
robotlegs
intersect
web-farm
os.system
subgraph
virtualpathprovider
node-redis
denied
fsevents
drawtobitmap
cgbitmapcontextcreate
commerceserver2007
instantiationexception
openfaces
blender-2.49
dsoframer
image-capture

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