Credential doesn't exist on Facebook Auth

Viewed 118

I'm copying this code from the expo documentation page Using Firebase (Facebook-Login) to integrate Facebook login with firebase.

const { type, token } = await Facebook.logInWithReadPermissionsAsync({
                                  permissions: ['public_profile'],
                              });
      
if (type === 'success') {
    const facebookAuthProvider = new FacebookAuthProvider();
    const credential = facebookAuthProvider.credential();
}

But when i copy this, having all the dependencies installed it says that :

  • Property 'token' does not exist on type 'FacebookLoginResult'
  • Property 'credential' does not exist on type 'FacebookAuthProvider'

But when i enter to the node-modules they do exist, idk what is happening or if i am doing something wrong, help.

1 Answers

When you call the function signInWithCredentials you should also pass the auth parameter which you will get by

const auth = getAuth();

// Listen for authentication state to change.
onAuthStateChanged(auth, user => {
  if (user != null) {
    console.log('We are authenticated now!');
  }

  // Do other things
})

and You also have to make some changes in FacebookAuthProvider

 await initializeAsync({ appId: <PP_ID> });

    const { type, token } = await logInWithReadPermissionsAsync({
      permissions: ['public_profile'],
    });

    if (type === 'success') {
      const credential = FacebookAuthProvider.credential(token)
signInWithCredential(auth, credential)
       .catch(error => console.log(error);
    }
Related