Home>

I'm trying to perform a Facebook login on Cognito on iOS and Android using ionic.

According to the reference, there was a web (Javascript) method, so I learned it.

To use Javascript SDK

<script>
    window.fbAsyncInit = function () {
      FB.init ({{
        appId: ‘1160583684336834’,
        autoLogAppEvents: true,
        xfbml: true,
        version: ‘v9.0’
      });
    };
    (function (d, s, id) {
       var js, fjs = d.getElementsByTagName (s) [0];
       if (d.getElementById (id)) {return;}
       js = d.createElement (s);js.id = id;
       js.src = "https://connect.facebook.net/ja_JP/sdk.js";
       fjs.parentNode.insertBefore (js, fjs);
     } (Document, ‘script’, ‘facebook-jssdk’));
</script>

Was added.

And I thought I would write the login process, but I'm stuck with where to add this.

  FB.login (function (response) {
      // handle the response
    });


Since the normal page is written in Typescript, if you add it as it is

Can not find'FB'.

I get the error message.

If anyone knows how to convert the login code to Typescript, add it as Javascript, or define FB, please comment.

Finally, I want to use my Facebook account to create a user in Cognito's user pool so that I can log in. If i find that the direction is wrong, please point it out.

  • Answer # 1

    If you are building iOS/Android with Cordova/Capacitor, you cannot use the script tag. Also, Oauth2 redirection cannot be used, so

    https://github.com/capacitor-community/facebook-login

    Please use a plug-in like.