我正在使用该flutter_facebook_auth 3.5.0
插件使用户能够使用他们的 Facebook 帐户登录我的应用程序。
一切都按预期工作。但是当我注销并尝试再次登录时,它不会提示我输入凭据并直接让我登录。
我希望它提示用户输入他们的 Facebook 帐户凭据,然后仅在身份验证成功时才登录应用程序。
下面是登录代码:
Future<void> signInWithFacebook(BuildContext context) async {
User? firebaseUser;
LoginResult response = await FacebookAuth.instance.login();
AuthCredential facebookCredential = FacebookAuthProvider.credential(response.accessToken!.token);
final UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(facebookCredential);
firebaseUser = userCredential.user;
switch (response.status) {
case LoginStatus.success:
final userData = await FacebookAuth.instance.getUserData();
facebookUserData = userData;
firestoreInstance.collection("users").doc(firebaseUser!.uid).set({
"userID": firebaseUser.uid,
"name": facebookUserData["name"],
"photo": facebookUserData["picture"]["data"]["url"],
"emailAddress": facebookUserData["email"],
"signUpMethod": "facebook",
"accountCreatedOn": Timestamp.now(),
"receiveOffers": true,
"isAdmin": false,
"isAuth": false,
"isSubscribed": false,
});
Navigator.of(context).pushReplacement(ScaledAnimationPageRoute(HomePage()));
break;
case LoginStatus.cancelled:
print("Facebook: User cancelled login");
break;
case LoginStatus.failed:
print("Facebook: Login error!");
break;
case LoginStatus.operationInProgress:
// TODO: Handle this case.
break;
}
}
下面是注销的方法:
await FacebookAuth.instance.logOut();
facebookUserData = {};
await authInstance.signOut().then((value) => Navigator.of(context).pushReplacement(ScaledAnimationPageRoute(SignIn())));
我认为AuthCredential
需要在用户注销时清除。我不知道该怎么做。
我是 Flutter 的新手。我怎样才能解决这个问题?