@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SystemClock.sleep(2000); // Check network connection if (!Commons.isNetworkAvailable(getApplicationContext())) { SystemClock.sleep(1500); Commons.showToastMessage("No internet connection", getApplicationContext()); nextActivityAfterLogin(MainActivity.class); return; } // Check if there is already an authorisation for firebase which the user application have // logged in previously Firebase fbRef = new Firebase(Constants.FIREBASE_MAIN); SharedPreferences prefs; // if there is valid authorisation, redirect to next activity if (fbRef.getAuth() != null) { prefs = getSharedPreferences(Constants.SHARE_PREF_LINK, MODE_PRIVATE); String role = prefs.getString(Constants.SHAREPREF_ROLE, null); String phoneNo = prefs.getString(Constants.SHAREPREF_PHONE_NO, null); if (phoneNo == null || role == null) { fbRef.unauth(); nextActivityAfterLogin(MainActivity.class); } else retrieveAccountInfo(phoneNo, role); } else { nextActivityAfterLogin(MainActivity.class); } }
/** Logout the user. */ public void logOut(MenuItem item) { Intent login = new Intent(this, LoginActivity.class); this.currFragment = null; mGlobalVariables.setUser(null); this.startActivity(login); this.finish(); Firebase ref = new Firebase(mGlobalVariables.getFirebaseUrl()); ref.unauth(); }
/** * *********************************************************************************************** * Method: logout Description: Logs out the user from their current session and starts * MainSignInActivity. Also disconnects the mGoogleApiClient if connected and provider is Google * Parameters: N/A Returned: N/A * ********************************************************************************************** */ protected void logout() { /* Logout if mProvider is not null */ if (mProvider != null) { // unauthorize the firebase user mFirebaseRef.unauth(); bUsingOffline = true; if (mProvider.equals(Constants.GOOGLE_PROVIDER)) { /* Logout from Google+ */ Auth.GoogleSignInApi.signOut(mGoogleApiClient) .setResultCallback( new ResultCallback<Status>() { @Override public void onResult(Status status) { // nothing } }); } } }
private void onFacebookAccessTokenChange(AccessToken token) { if (token != null) { ref.authWithOAuthToken( "facebook", token.getToken(), new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { // The Facebook user is now authenticated with your Firebase app } @Override public void onAuthenticationError(FirebaseError firebaseError) { // there was an error } }); } else { /* Logged out of Facebook so do a logout from the Firebase app */ ref.unauth(); } }
public void disconnect() { isConnected = false; firebase.unauth(); }