I have started using Flutter this year, so I am not an expert. I am trying to develop an app for both Android and iOS that includes login with Google and Facebook using Firebase Auth.
First I wrote the code in Android Studio in Windows and it works, but when I write it in Android Studio in macOS some lines of code don't work properly. I have configured the iOS project on the Firebase console and on Facebook for developers 'console'. I didn't use CocoaPods to add the frameworks, but I did it manually on Xcode.
Basically, the error is: The method 'signInWithFacebook' isn't defined for the class 'FirebaseAuth'.
Yes, the method signInWithFacebook
is gone from FirebaseAuth
now we do this work with signInWithCredential
method with AuthCredential
and FacebookAuthProvider
classes to make autentication process. I will put a snipet with some comments just to illustrate how to do auth in firebase with facebook credentials. I hope it helps...
/// in some point of your code you will get facebookLoginResult
final facebookLoginResult = await facebookLogin
.logInWithReadPermissions(['email', 'public_profile']);
FacebookAccessToken myToken = facebookLoginResult.accessToken;
///assuming sucess in FacebookLoginStatus.loggedIn
/// we use FacebookAuthProvider class to get a credential from accessToken
/// this will return an AuthCredential object that we will use to auth in firebase
AuthCredential credential= FacebookAuthProvider.getCredential(accessToken: myToken.token);
// this line do auth in firebase with your facebook credential.
FirebaseUser firebaseUser = (
await FirebaseAuth.instance.signInWithCredential(credential)
).user;
/// ... do your things
signInWithFacebook is no longer exist. This is work perfectly! flutter_facebook_login 3.0.0
final FacebookLoginResult facebookLoginResult = await facebookLogin.logIn(['email', 'public_profile']);
FacebookAccessToken facebookAccessToken = facebookLoginResult.accessToken;
AuthCredential authCredential = FacebookAuthProvider.getCredential(accessToken: facebookAccessToken.token);
FirebaseUser fbUser;
fbUser = (await _firebaseAuth.signInWithCredential(authCredential)).user;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With