Getting a weird error while using signInWithCredential(), but I am able to sign in by signInAnonymously()
Have tried searching and remaking app in facebookDeveloper account.
My Function:
Future<UserCredential> _signInWithFacebook() async {
final loginResult = await FacebookAuth.instance.login(permissions: [
'email',
'public_profile',
]);
if (loginResult.status == LoginStatus.success) {
final accessToken = loginResult.accessToken!.token;
final OAuthCredential credential =
FacebookAuthProvider.credential(accessToken);
return await FirebaseAuth.instance
.signInWithCredential(credential)
.then((value) {
Navigator.pushReplacementNamed(context, '/home');
return value;
});
} else {
return FirebaseAuth.instance.signInAnonymously();
}
}
Error:
FLTFirebaseAuth: An error occurred while calling method Auth#signInWithCredential, errorOrNil => (null)
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: [firebase_auth/unknown] An unknown error has occurred.
#0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:607
#1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:167
<asynchronous suspension>
#2 MethodChannel.invokeMapMethod
package:flutter/…/services/platform_channel.dart:367
<asynchronous suspension>
#3 MethodChannelFirebaseAuth.signInWithCredential
package:firebase_auth_platform_interface/…/method_channel/method_channel_firebase_auth.dart:433
<asynchronous suspension>
#4 FirebaseAuth.signInWithCredential
package:firebase_auth/src/firebase_auth.dart:497
<asynchronous suspension>
CodePudding user response:
The following steps can be helpful if you haven't tried it yet -
- Check if the firebase app is instantiated at the beginning -> .initializeApp()
- Firebase Auth doesn't work without initialization
- If the above two doesn't work, replace google-services.json with a new one. Do a clean build