Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function SignInWithFacebook doesn't exist in Firebase Auth SDK for Flutter in macOS, but in Windows it exists

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'.

screenshot

like image 374
Gabriele Guccione Avatar asked Nov 27 '22 20:11

Gabriele Guccione


2 Answers

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
like image 51
Marcos Boaventura Avatar answered Dec 14 '22 23:12

Marcos Boaventura


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;
like image 24
Mahinthan177 Avatar answered Dec 14 '22 23:12

Mahinthan177