Proper way to logout with react-native-fbsdk
Asked Answered
M

2

6

I am using react-native-fbsdk to login through facebook on my react-native app.
I call LoginManager.logOut() to logout: it does not actually properly logout since the next time I try to login, it does not ask me for login/password again so I can only login on one account. I can not find a way to login to another facebook account.

This guy (react-native-fbsdk: How properly log out from facebook?) had the same problem and seem to have found no solution.

One trick on iOS is to go to safari then logout from the mobile facebook website. This does not work on android though :(

EDIT:

Here is my facebook login code:

function login() {
  return LoginManager.logInWithReadPermissions(FACEBOOK_PERMISSIONS)
    .then(result => {
      if (result.isCancelled) {
        throw new Error("Login canceled");
      }
      return AccessToken.getCurrentAccessToken();
    })
    .then(({ accessToken }) => accessToken);
}

Video of logout/login: https://d3vv6lp55qjaqc.cloudfront.net/items/132L2U1p383E1y0l2l2v/Screen%20Recording%202018-10-31%20at%2002.52%20PM.mov

Mcgary answered 29/7, 2018 at 21:22 Comment(4)
Did you found a solution ?Nejd
@zarnifoulette Not a solution but a hack: if you use the web behavior instead, it asks for login again. const webLoginBehavior = Platform.OS === "ios" ? "web" : "WEB_ONLY"; LoginManager.setLoginBehavior(webLoginBehavior);Mcgary
I found a solution, actually you need to do a GraphRequest if you want to logout. I will write for you a proper solution.Nejd
I forgot to respond you but yes I have got the same problem. For the moment that is not a problem for me. But if you find a solution I will be glad to hear it :)Nejd
N
4

So I found this solution, that is not a hack but the proper way to perform a logout on facebook. You need to create a GraphRequest to ask a deletion of permissions. Below the code, I hope that will help you. I test it on Android and IOS, and that work like a charm.

    FBLogout = (accessToken) => {
        let logout =
            new GraphRequest(
                "me/permissions/",
                {
                    accessToken: accessToken,
                    httpMethod: 'DELETE'
                },
                (error, result) => {
                    if (error) {
                        console.log('Error fetching data: ' + error.toString());
                    } else {
                        LoginManager.logOut();
                    }
                });
        new GraphRequestManager().addRequest(logout).start();
    };
Nejd answered 19/10, 2018 at 12:35 Comment(5)
It does logout but when I try to login again, it does not asks for email or password, I can only re-login with the same user. :(Mcgary
Could you show me some screenshots and your code to login ?Nejd
Hi, guys. @zarnifoulette any solutions for this? I tried the graph request proposal above but as httpete says it is not asking for any kind of confirmation on the second attempt.Brewery
Hello guys, I have post a github issue for that, you can follow it here github.com/facebook/react-native-fbsdk/issues/507Nejd
@Nejd Thanks for opening the issue. I've followed it up with a touch of well-deserved aggression.Beaconsfield
I
1

The problem is not with react-native-fbsdk but with Facebook or the browser through which the user logs in to connect to your app, the reason being every-time your app accesses the Facebook login through the browser or the Facebook app where the user-account is already logged-in, which is why it doesn't show you username or password fields.

To solve this issue, the user must logout from the browser or Facebook through which he/she logged in (for app permission initially) to your app, so when the user comes back to your app and selects the Facebook-login option, assuming user logged-out of your app as well, then he/she can see it redirecting to the Facebook or browser login page with username and password fields.

Issiah answered 2/7, 2020 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.