0
votes

I am using Facebook Login in my Flutter app. I have followed the implementation steps and my app successfully brings up a Facebook Login dialogue and returns an access token on successful login. I don't think the user is actually authenticated on Firebase yet: No new user is listed in the Authentication/Users page on the Firebase console, and calling FirebaseUser user returns null.

The documentation on FlutterFire (https://firebase.flutter.dev/docs/auth/social/) provides this method for authenticating the user on Firebase:

import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';

Future<UserCredential> signInWithFacebook() async {
  // Trigger the sign-in flow
  final LoginResult result = await FacebookAuth.instance.login();

  // Create a credential from the access token
  final FacebookAuthCredential facebookAuthCredential =
    FacebookAuthProvider.credential(result.accessToken.token);

  // Once signed in, return the UserCredential
  return await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
} 

I have added this method to my app. The problem is that even though I have the right package in my pubspec.yaml...

dependencies:
  flutter_facebook_auth: "^1.0.0"

...I am getting these errors on the code from FlutterFire:

" Undefined class 'FacebookAuthCredential' "

and

" The method 'credential' isn't defined for the type 'FacebookAuthProvider'. "

Other methods from flutter_facebook_auth work fine, though (eg FacebookAuth.instance.login())

I would appreciate any help!

1

1 Answers

1
votes

Solved it! I just needed to add this plugin: firebase_auth_platform_interface: ^3.1.0 (https://pub.dev/packages/firebase_auth_platform_interface)

This gave me access to the FacebookAuthCredential object.

The FacebookAuthProvider.credential() method still wasn't available, but I replaced it with FacebookAuthProvider.getCredential() and it worked as it is supposed to.