【发布时间】:2021-03-07 18:00:20
【问题描述】:
我正在尝试但未能重新触发用户在删除用户后使用 Google 登录对自己进行身份验证时所执行的身份验证步骤。在第二次使用 Google 登录时,被删除的用户只需立即登录(而不是通过身份验证步骤)。我希望能够为自己的测试目的重新触发身份验证步骤。
具体来说,我有一个用户,我已经按照FlutterFire documentation 进行了身份验证和登录,即
Future<UserCredential> signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
// Create a new credential
final GoogleAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(credential);
}
然后我继续删除用户;再次,根据FlutterFire documentation,即
try {
await FirebaseAuth.instance.currentUser.delete();
} catch on FirebaseAuthException (e) {
if (e.code == 'requires-recent-login') {
print('The user must reauthenticate before this operation can be executed.');
}
}
这行得通,因为用户不再列在 Firebase 控制台中经过身份验证的用户中。 然而,如果我现在再次调用 signInWithGoogle(),那么用户不会再次通过身份验证步骤(即被提示输入电子邮件、密码等),而是只需签名即可马上。就好像用户没有被正确删除一样。我将如何重新触发身份验证步骤?
【问题讨论】:
-
删除后注销用户。
-
@DougStevenson 我现在刚刚尝试过,即在
await FirebaseAuth.instance.currentUser.delete();之后立即调用await FirebaseAuth.instance.signOut()。我仍然看到相同的行为。 -
可能流程有点自动化,这意味着如果您使用物理设备进行测试,Google 的身份验证凭据会被重新识别?
-
@Julian2611 我正在用安卓模拟器测试它。
-
我明白了。你能以某种方式验证模拟器不记得你的谷歌登录凭据吗?也许通过重置一些设置?因为我认为这可能是问题所在,因为我在使用 firebase 和 Angular 时观察到了类似的行为。
标签: firebase flutter authentication firebase-authentication google-signin