I'm trying to add firebase and facebook authentication in my app. Facebook auth is already done:
final facebookLogin = FacebookLogin();
final result = await facebookLogin.logInWithReadPermissions(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final token = result.accessToken.token;
final graphResponse = await http.get(
'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=$token');
Map<String, dynamic> user = jsonDecode(graphResponse.body);
// _onGetFacebookUser(user);
I don't know how to perform firebase authentication with facebook result.
I've already watched this answer, but it doesn't help, there is only facebook login code example.
I've found this article, but there is no method signInWithFacebook
You have to use credential
final result = await facebookLogin.logInWithReadPermissions(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final token = result.accessToken.token;
AuthCredential fbCredential = FacebookAuthProvider.getCredential(accessToken: token);
FirebaseAuth.instance.signInWithCredential(credential).then((FirebaseUser user) {
// do something...
});
...
UPD:
It worked fine for flutter_facebook_login
version 2.0.1
For now for version 3.0.0 there is method 'login':
final result = await facebookLogin.logIn(['email']);
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