我正在开发一个应用程序,我想在其中添加功能以从Firebase中删除用户。我遵循官方文档,但我不能这样做。我在控制台中收到警告
错误此操作敏感,需要最近的身份验证。重试此请求之前,请再次登录。
这是我的代码:
- (void)deleteUser {
FIRUser *user = [FIRAuth auth].currentUser;
[user deleteWithCompletion:^(NSError *_Nullable error) {
if (error) {
NSLog(@"Error %@", error.localizedDescription);
} else {
NSLog(@"Delete user");
}
}];
}
也许有人遇到类似的问题,告诉我如何解决?”
最佳答案
在网站上查看Firebase api的文档,您可以看到您要删除的代码在Firebase中必须最近登录。
如果您登录了一段时间。您必须重新认证。
这是如何重新认证:
FIRUser *user = [FIRAuth auth].currentUser;
FIRAuthCredential *credential;
// Prompt the user to re-provide their sign-in credentials
[user reauthenticateWithCredential:credential completion:^(NSError *_Nullable error) {
if (error) {
// An error happened.
} else {
// User re-authenticated.
}
}];
在对安全敏感的操作中,例如(删除用户,设置密码,设置电子邮件...),您必须首先重新认证。
关于ios - 无法从Firebase中删除用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42321508/