facebookarchive / react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
https://developers.facebook.com/docs/react-native
Other
2.99k stars 908 forks source link

onLoginFinished never is fired #687

Closed CharlyJazz closed 4 years ago

CharlyJazz commented 4 years ago
import React, {Component} from 'react';
import {View} from 'react-native';
import {LoginButton, AccessToken} from 'react-native-fbsdk';
import get_user_by_email from '../services/get_user_by_email';

export default class FBLoginButton extends Component {
  render() {
    return (
      <View
        style={{
          justifyContent: 'center',
          height: 80,
          alignItems: 'center',
        }}>
        <LoginButton
          publishPermissions={['email']}
          onLoginFinished={(error, result) => {
            if (error) {
              console.log('login has error: ' + result.error);
            } else if (result.isCancelled) {
              console.log('login is cancelled.');
            } else {
              AccessToken.getCurrentAccessToken().then(data => {
                console.log(data.accessToken.toString());
              });
            }
          }}
          onLogoutFinished={() => alert('User logged out')}
        />
      </View>
    );
  }
}

module.exports = FBLoginButton;

This code was copypasted from the README. And not work. BUT onLogoutFinished its called perfectly.

Env

"react": "16.9.0",
"react-native": "0.61.5",
"react-native-fbsdk": "^1.1.1"
tsirolnik commented 4 years ago

Having the same issue -

<LoginButton
              permissions={["email"]}
              onLoginFinished={() => Alert.alert("User logged in")}
              onLogoutFinished={() => Alert.alert("User logged out")} />

"react-native-fbsdk": "^1.1.1" react: 16.8.6 => 16.8.6 react-native: 0.60.5 => 0.60.5

onLogoutFinished is called, but not onLoginFinished

Though the button's text does change to "Log out"

Using the LoginManager (as shown here) does invoke the correct callback

edwardhsueh commented 4 years ago

Hi, I found a strange behavior. The onLoginFinished is issued in release mode(react-native run-android --variant=release), but NOT in debug mode.

gmertk commented 4 years ago

I was not able to repro this on Android or iOS with the following versions. Facebook app wasn't installed.

  {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-fbsdk": "^1.1.2"
  }
stefandima commented 4 years ago

This reproduce on android exactly with

{
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-fbsdk": "^1.1.2"
  }

To reproduce this, you must reload once the application. If i delete all the data saved by the application, onLoginFinished is called. If i shake the device, and chose reload, when i try to login onLoginFinished is not called anymore. The login is done with success. Button changes from "Continue with facebok" into "Disconnect". If i reload again the app, because i check in constructor if i'm logged in, i will be logged in. Problem is that at login, only the button is changed, not the rest of the screen, because my state doesn't change anymore via onLoginFinished. I tried to find if another event is fired, but without success.

Harsh-Choudhary-01 commented 4 years ago

I also have this issue, seems like it's something to do with reloading/debugging the app.

samipshah100 commented 4 years ago

Same issue here in debugging mode. It was called the first time so I assume its because of the data stored in app. It's going to be painful to re build react native everytime I want to debug this. Any other suggestions?

stefandima commented 4 years ago

As a work around, I don't use reload function of the client. If I want a refresh, I either close the app, remove from recent opened apps, and open again the app, either use the auto refresh option by changing something in the code, and app will refresh to new code. HTH

samipshah100 commented 4 years ago

Do you mean the live reload?

samipshah100 commented 4 years ago

@stefandima can you please elaborate, because closing app and opening again doesn't work for me.

stefandima commented 4 years ago

Solution is to rebuild now the application. Install again on the device, and after that never use the reload option directly from application. If you will need a reload after that, either close the app, remove from memory, and start again (sometime is needed because is loosing connection with the Metro Server), either relay on live reload. Never:

Jaffarraza12 commented 4 years ago

I have done that remove app from device and build again .Issue persist OnLoginFinished never firing.

samipshah100 commented 4 years ago

Gradlew clean and run react native run Android again

On Sat, 2 May, 2020, 3:01 pm Jaffarraza12, notifications@github.com wrote:

I have done that remove app from device and build again .Issue persist OnLoginFinished never firing.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native-fbsdk/issues/687#issuecomment-622925850, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMJ3FQHXCOOLONQKXALX5F3RPPR5ZANCNFSM4KAE46XQ .

Jaffarraza12 commented 4 years ago

I found my problem after going through this.https://github.com/facebook/react-native-fbsdk In my MainActivity class I was using CallbackManager instance locally initiated. After referring to CallbackManager instance of MainApplication class, onLoginFinished functioned triggered!! :)

please refer : https://reactnativecode.com/facebook-login-integration/

nastari commented 4 years ago

the problem is that it fires once and then creates some cache somewhere and it ignores onLoginFinish, but I need to retest the server's responses. The callback works, but some problem in the memory

afouchet commented 4 years ago

I found my problem after going through this.https://github.com/facebook/react-native-fbsdk In my MainActivity class I was using CallbackManager instance locally initiated. After referring to CallbackManager instance of MainApplication class, onLoginFinished functioned triggered!! :)

please refer : https://reactnativecode.com/facebook-login-integration/

Tried this, did not work for me :-(

afouchet commented 4 years ago

I have the issue with :

afouchet commented 4 years ago

@CharlyJazz Can you tell us why you closed the issue ? I still have the problem. Did you fix it ?

Personnally, I went around it in a dirty way : On the screen with the LoginButton, I asked every 0.1s fbsdk's AccessToken.getCurrentAccessToken -> if it returns something, I can log my user (because he is logged in).

But I'd rather have an event fired on onLoginFinished ...

ZeeshanAhmadKhalil commented 3 years ago

I was facing the same problem, the problem was that I didn't enter my hash key while enabling Facebook login also I didn't tell my Package Name and Default Activity Class Name.

Just make sure you follow all the steps in Quick Start after enabling the Facebook login, you might missing something or doing something wrong while following Quick Start.

Like I am still doing now and getting Error The key hash does not match any stored key hashes. To resolve this error I am going through #424 I am sure I will find a solution :)