Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login is not working in "facebook mobile browser" on facebook android app(not facebook lite) #303

Open
IndraVikas opened this issue Jun 18, 2020 · 36 comments

Comments

@IndraVikas
Copy link

I am facing this issue in facebook mobile browser. When I click a link in the Facebook app (not the Facebook lite app). It opens the URL in the "Facebook mobile browser". Login in this browser is not working.
I am using the following setting.

<FacebookLogin appId={ config.FACEBOOK_APP_ID } autoLoad={ false } fields="name,email,picture" callback={ this.facebookResponse } cssClass="btnFacebook" isMobile={ false } disableMobileRedirect icon={ <i className="fa fa-facebook" style={ { marginLeft: "5px" } } /> } textButton="&nbsp;&nbsp;Login with Facebook" />

Note. It is working in chrome or other browsers on mobile. It is also working from the Facebook lite app. because it opens the URL in the chrome browser.

Please help it's very critical for my project. Do let me know if more details are required.

Thanks in Advance

@Dezzymei
Copy link

Same issue

@Dezzymei
Copy link

Dezzymei commented Jun 19, 2020

I think this is because by default it uses the user agent and it could be outdated:

isMobile = !!((window.navigator && window.navigator.standalone) || navigator.userAgent.match('CriOS') || navigator.userAgent.match(/mobile/i));

But perhaps it should be something else:
Like here

@gmarokov
Copy link

I have the same issue. Does anyone came up with a fix for this?

@ilan0888
Copy link

ilan0888 commented Jul 3, 2020

i also have this same issue, any update?

@guigeekz
Copy link

guigeekz commented Jul 9, 2020

Same here, it is also very critical for my project, any one has some news on this ?

Thanks

@ilan0888
Copy link

ilan0888 commented Jul 9, 2020

Same here, it is also very critical for my project, any one has some news on this ?

Thanks

I have a solution and it is to start using the redirect method instead of the popup. after the redirect you have access from the url to the idToken or the AccessToken depends on the prop you give to the component and then just use a hook on the route you want it to redirect that parses the query string and make the request to your backend,
this is working in facebook in app webview and all the other senerios i had problems with.

@guigeekz
Copy link

Same here, it is also very critical for my project, any one has some news on this ?
Thanks

I have a solution and it is to start using the redirect method instead of the popup. after the redirect you have access from the url to the idToken or the AccessToken depends on the prop you give to the component and then just use a hook on the route you want it to redirect that parses the query string and make the request to your backend,
this is working in facebook in app webview and all the other senerios i had problems with.

@ilan0888 could you please share the code in order to help to integrate this !

Thanks in advance

@IndraVikas
Copy link
Author

@ilan0888 can you please share the code. It will be a great help.

@alcidesbsilvaneto
Copy link

I was having a similar issues, wich I solved using disableMobileRedirect={true}

@ronytesler
Copy link

I was having a similar issues, wich I solved using disableMobileRedirect={true}

So you solved it by disabling the mobile redirect, and @ilan0888 solved it by enabling it?
@guigeekz , @ilan0888 , @alcidesbsilvaneto , can you please share your code?

@nelsonfleig
Copy link

@ronytesler Yeah I've also been reading contradicting solutions. Others have suggested setting isMobile={false} or using other methods to detect the user agent, since the mobile browser may not be recognized properly by react-facebook-login.

@ronytesler
Copy link

Yes, I'm going to try the accepted answer here:
https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
Have you tried it?

@nelsonfleig
Copy link

Not yet, but I believe we also need to look for the Instagram or Facebook browser. Something similar to this:

For Facebook: https://stackoverflow.com/questions/31569518/how-to-detect-facebook-in-app-browser
For Instragram: https://supergeekery.com/blog/detecting-the-instagram-in-app-browser

Waiting for my client to show the link to our site on his IG account again so I can do some testing. Let me know if you have any luck.

@ronytesler
Copy link

@Kokopelli84 If there's a problem with mobile detection, we need to set isMobile={true}, no? Because we're running on mobile.

@nelsonfleig
Copy link

nelsonfleig commented Sep 1, 2020

@ronytesler I just tried it and setting isMobile={true} doesn't work as well. I used the following code to hide the facebook login for my client on FB and IG in-app browsers. Maybe it will help someone until we can come up with a stable solution.

Using this question on Stackoverflow as a reference, on your login component you can use this function to detect if we are on the FB or IG in-app browser:

const isFacebookApp = () => {
    const ua = navigator.userAgent || navigator.vendor || window.opera;
    return ua.indexOf('FBAN') > -1 || ua.indexOf('FBAV') > -1 || ua.indexOf('Instagram') > -1;
  };

Then use it to conditionally render your Facebook component inside your Login component:

{!isFacebookApp() && <Facebook />}

I believe though that the answer might be setting disableMobileRedirect={false}, parsing the query params and using these to handle your login like @ilan0888 mentioned. Will give it a try and post my code soon.

@jackkidding
Copy link

jackkidding commented Sep 1, 2020

try it

<FacebookLogin
    ...
    redirectUri='yourRedirectUri'
    disableMobileRedirect={!isFacebookApp()} />

@ronytesler
Copy link

@jackkidding How did you implement it? I don't see any example or explanation. Can you share your code?

@ronytesler
Copy link

@jackkidding I think it works, thanks!

@nelsonfleig
Copy link

nelsonfleig commented Sep 8, 2020

@jackkidding It is kind of working for me on the IG in-app browser, but with a few glitches. The first time I press "Log in with FB" it takes me to FB to login where it asks for my email and password. Then it redirects me back to my app, but does not log in to my app. After clicking on the "Log in with FB" button again, THEN it works and without having to enter my email and password on FB! Now I just have to figure out how to make it work on the first log in attempt...

@ronytesler
Copy link

@Kokopelli84 Maybe you can use autoLoad={true} and add a flag to the redirectUri that tells your app to do a refresh, then it will hopefully login automatically.
I have a new and not related problem - when I use autoLoad={true} it makes the Login Popup pop without clicking anything (not on refresh, just when I go to the website normally).

@IndraVikas
Copy link
Author

@ronytesler @jackkidding
can you please share the config. I am using the following configuration and it is not working.

<FacebookLogin appId={ config.FACEBOOK_APP_ID } autoLoad={ false } fields="name,email,picture" callback={ this.facebookResponse } cssClass="btnFacebook" isMobile={ false } disableMobileRedirect={ false } icon={ <i className="fa fa-facebook" style={ { marginLeft: "5px" } } /> } textButton="&nbsp;&nbsp;Login with Facebook" /> </div>

@ronytesler
Copy link

@IndraVikas I think it's not working for you because you have isMobile={false}.
This is mine:

isFacebookApp = () => {
const ua = navigator.userAgent || navigator.vendor || window.opera;
return ua.indexOf('FBAN') > -1 || ua.indexOf('FBAV') > -1 || ua.indexOf('Instagram') > -1;
};

        <FacebookLogin
            disableMobileRedirect={!this.isFacebookApp()}
            redirectUri={"https://watoobi.appspot.com/"}
            state={window.location.search} // pass the current query string to the redirect.
            appId={appId}
            autoLoad={false}
            fields="name,picture"
            onClick={this.componentClicked}
            callback={this.responseFacebook}
            render={(renderProps) => (
                <button type="button" onClick={renderProps.onClick}>{lan.buttons.facebook}</button>
            )}/>

@IndraVikas
Copy link
Author

@ronytesler I tried the above solution It is not working for me. :(
Please note that it is working in the Facebook Lite app but not in the Facebook app. because in the lite app the URL is opened in chrome powered browser. while in the Facebook app it is getting opened in a browser powered by Facebook.

`
const isFacebookApp = () => {
const ua = navigator.userAgent || navigator.vendor || window.opera;
return ua.indexOf("FBAN") > -1 || ua.indexOf("FBAV") > -1 || ua.indexOf("Instagram") > -1;
};

<FacebookLogin
disableMobileRedirect={! isFacebookApp()}
appId={ config.FACEBOOK_APP_ID }
autoLoad={ false }
fields="name,email,picture"
callback={ this.facebookResponse }
cssClass="btnFacebook"
redirectUri="https://prepsutra.com"
state={ window.location.search }
icon={ <i className="fa fa-facebook" style={ { marginLeft: "5px" } } /> }
textButton="  Login with Facebook"
/>`

@ronytesler
Copy link

@IndraVikas Nothing happens when you click the login button?
Just to make sure, try disableMobileRedirect={false} and isMobile={true}
Are you on iPhone?

@IndraVikas
Copy link
Author

@ronytesler
I am using an android.
When I click the login button it redirects me to the following URL. The callback function "this.facebookResponse" is not getting invoked.

https://prepsutra.com/?code=AQAM-cRfrQXsel6a2QkyiOobaxZsNMiXgC8iTKgP3j3u3uLgL4Sw7moCmLTzBn73neFScc9ITqqEfGFyQ7RUUave8MeMp0MhyN_XYmv_OfK3rLZl1V8b_oni-NHatD-ZTTroEtd6WNPyKVpwBzPeZ_W-4ET0T#_=_

@ronytesler
Copy link

@IndraVikas try removing the state if you don't need it.
did you clear the cache in the browser and put a breakpoint in the correct place in developer tools?

@ghost
Copy link

ghost commented Oct 1, 2020

Same issue

  1. isMobile={false}
  2. disableMobileRedirect={true}
    This params didn't help
    <FacebookLogin fields="name,email,picture" isMobile={false} disableMobileRedirect={true} callback={this.responseFacebook} render={(renderProps) => ( <Button onClick={renderProps.onClick} className="facebook big login-button" > Facebook </Button> )} />

@ronytesler
Copy link

@frontend-oleh-k No, you should use disableMobileRedirect={false}. isMobile is automatically detected.
This is mine:
isFacebookApp = () => {
const ua = navigator.userAgent || navigator.vendor || window.opera;
return ua.indexOf('FBAN') > -1 || ua.indexOf('FBAV') > -1 || ua.indexOf('Instagram') > -1;
};

<FacebookLogin
disableMobileRedirect={!this.isFacebookApp()} // false if using the Facebook browser
redirectUri={"https://mywebsite.com/"}
state={window.location.search}
appId="470..."
autoLoad={false}
fields="name,picture"
onClick={this.componentClicked}
callback={this.responseFacebook}
render={(renderProps) => (
{lan.buttons.facebook}
)}/>

@brunoqs
Copy link

brunoqs commented Oct 14, 2020

@ronytesler i used this last config you sent above, but it doesnt work for iphone, just for android and desktop. Its same for u?

@ronytesler
Copy link

for me it works on iPhone.. on which browser did you try, Facebook Messenger's?
what happens exactly?
did you try isMobile={true} and check if works?

@brunoqs
Copy link

brunoqs commented Oct 15, 2020

yes i tried with isMobile={true}, im login using safari browser and its worked just on iphone 8, on iphone 11 it doesnt worked.

@NPZlatu
Copy link

NPZlatu commented Oct 23, 2020

I have been struggling through this issue for pretty much time. After multiple hit and trial the following configuration works for me.

const isFacebookApp = () => {
  const ua = navigator.userAgent || navigator.vendor || window.opera;
  return (
    ua.indexOf('FBAN') > -1 ||
    ua.indexOf('FBAV') > -1 ||
    ua.indexOf('Instagram') > -1
  );
};
         <FacebookLogin
          appId={FACEBOOK_APP_ID}
          autoLoad={isFacebookApp()}  //auto load had to be true for facebook browser
          disableMobileRedirect={!isFacebookApp()}
          redirectUri={'https://bpazes.com/'}  //had to give this
          fields="name"
          callback={loginByFb}
          render= .....
     />

@EduardoUstarez
Copy link

EduardoUstarez commented Dec 20, 2020

I have been struggling through this issue for pretty much time. After multiple hit and trial the following configuration works for me.

const isFacebookApp = () => {
  const ua = navigator.userAgent || navigator.vendor || window.opera;
  return (
    ua.indexOf('FBAN') > -1 ||
    ua.indexOf('FBAV') > -1 ||
    ua.indexOf('Instagram') > -1
  );
};
         <FacebookLogin
          appId={FACEBOOK_APP_ID}
          autoLoad={isFacebookApp()}  //auto load had to be true for facebook browser
          disableMobileRedirect={!isFacebookApp()}
          redirectUri={'https://bpazes.com/'}  //had to give this
          fields="name"
          callback={loginByFb}
          render= .....
     />

thanks It works to me. autoLoad={true} works in Facebook Browser, and in chrome or desktop browser autoLoad={false}
in a certain way solves the problem.

@ssxenon01
Copy link

I have been struggling through this issue for pretty much time. After multiple hit and trial the following configuration works for me.

const isFacebookApp = () => {
  const ua = navigator.userAgent || navigator.vendor || window.opera;
  return (
    ua.indexOf('FBAN') > -1 ||
    ua.indexOf('FBAV') > -1 ||
    ua.indexOf('Instagram') > -1
  );
};
         <FacebookLogin
          appId={FACEBOOK_APP_ID}
          autoLoad={isFacebookApp()}  //auto load had to be true for facebook browser
          disableMobileRedirect={!isFacebookApp()}
          redirectUri={'https://bpazes.com/'}  //had to give this
          fields="name"
          callback={loginByFb}
          render= .....
     />

thanks this fixed Facebook App Browser issue, but on Messenger issue still remains.

@Johnsonzhangc
Copy link

I have been struggling through this issue for pretty much time. After multiple hit and trial the following configuration works for me.

const isFacebookApp = () => {
  const ua = navigator.userAgent || navigator.vendor || window.opera;
  return (
    ua.indexOf('FBAN') > -1 ||
    ua.indexOf('FBAV') > -1 ||
    ua.indexOf('Instagram') > -1
  );
};
         <FacebookLogin
          appId={FACEBOOK_APP_ID}
          autoLoad={isFacebookApp()}  //auto load had to be true for facebook browser
          disableMobileRedirect={!isFacebookApp()}
          redirectUri={'https://bpazes.com/'}  //had to give this
          fields="name"
          callback={loginByFb}
          render= .....
     />

thanks this fixed Facebook App Browser issue, but on Messenger issue still remains.

Yes, Messenger still remains the same issue.

@OlyaKastsiukova
Copy link

@jackkidding It is kind of working for me on the IG in-app browser, but with a few glitches. The first time I press "Log in with FB" it takes me to FB to login where it asks for my email and password. Then it redirects me back to my app, but does not log in to my app. After clicking on the "Log in with FB" button again, THEN it works and without having to enter my email and password on FB! Now I just have to figure out how to make it work on the first log in attempt...

Have the same, did you find the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests