Search code examples
androidfacebookflutterfirebase-authentication

Flutter Firebase auth facebook not working


I'm trying to implement different login options for my flutter app users, but can't make the facebook one work(google and email are ok).

I've followed the installation guide from the package flutter_facebook_auth but still getting an error when the token provided from facebook is going to be used as a credential to create the firebase user:

enter image description here

my code:

import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
import 'package:firebase_auth/firebase_auth.dart';
final FirebaseAuth _auth = FirebaseAuth.instance;
String usermail = "";
Future returnToken(User user) async {
   token = word + await user.getIdToken();
}
  Future<List<String>> facebookSignin() async {
    try {
      final _instance = FacebookAuth.instance;
      final result = await _instance.login(permissions: ["email"]);
      if (result.status == LoginStatus.success) {
        final OAuthCredential credential = FacebookAuthProvider.credential(result.accessToken.token);
        final a = await _auth.signInWithCredential(credential); //the error is in this line
        await _instance.getUserData().then((userData) async {
          await _auth.currentUser.updateEmail(userData["email"]);
          userMail = userData["email"];
        });
        await returnToken(a.user);
        return ["ok"];
      } else if (result.status == LoginStatus.cancelled) {
        return ["Erro!", "Login cancelado"];
      } else
        return ["Erro!", "Falha no login"];
    } catch (e) {
      return ["Erro!", e.toString()];
    }
  }

Solution

  • The problem was on the secret key option: enter image description here

    I didn't add it on my app, so having this setting turned on blocked the app from generating a valid token to firebase.