PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 16, 2022

[FIXED] How to check if a user is logged in via Facebook in Firebase Auth

 July 16, 2022     android, facebook-login, firebase-authentication, java     No comments   

Issue

I am trying to determine whether the current user is authenticated in the app via Facebook login or not. I want that because if a user is authenticated via facebook than the signOut() should process

        LoginManager.getInstance().logOut();

but if it is authenticated via email than simple

auth.signOut();

my cuurent code is

//sign out method
public void signOut() {

    if(auth.getCurrentUser().getProviderId().equals("facebook.com")) {
        LoginManager.getInstance().logOut();
        auth.signOut();
    }
    else {
        auth.signOut();
    }
}

Solution

This is how you can do it:

if (firebaseUser != null) {
    for (UserInfo userInfo : firebaseUser.getProviderData()) {
        if (userInfo.getProviderId().equals("facebook.com")) {
            Log.d("TAG", "User is signed in with Facebook");
        }
    }
}


Answered By - Alex Mamo
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing