使用Phone Auth注册时如何注销/注销Firebase用户 [英] How to deregister / unregister Firebase user when registered using Phone Auth
问题描述
我已经使用Firebase便利FUIPhoneAuth注册了用户.当我尝试使用以下方法删除用户时:
I have registered users using Firebase convenience FUIPhoneAuth. When I try to delete the user with:
[user deleteWithCompletion:^(NSError * _Nullable error) ..
我收到一条错误消息,指出只能删除最近通过身份验证的用户.
"This operation is sensitive and requires recent authentication. Log in again before retrying this request."
为了注销用户,我首先需要重新认证需要FIRAuthCredential"credential"参数的用户:
In order to deregister the user, I first need to re-authenticate the user which requires a FIRAuthCredential "credential" parameter:
[user reauthenticateWithCredential:credential completion:^(NSError *_Nullable error) {
Firebase文档提到在调用委托时应该保存FIRAuthCredential.(将其存储在NSUserDefaults中)
Firebase doc mentions that one should save FIRAuthCredential when a delegate gets called.(store it in NSUserDefaults)
[[FIRPhoneAuthProvider provider] verifyPhoneNumber:userInput
UIDelegate:nil
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
我已将FUIPhoneAuth与signInWithPresentingViewController:一起使用,并且在注册时未收到FIRAuthCredential. 我在想,如果我可以掌握"FIRAuthCredential",则可以重新使用它 注销用户.但是,当使用 FUIPhoneAuth 时,这似乎是不可能的. *如何注销 FIRAuthCredential 以便注销用户?*
I have used FUIPhoneAuth with signInWithPresentingViewController: and did not receive a FIRAuthCredential upon registration. I am thinking that if I can get hold of the "FIRAuthCredential" I can re-use it to deregister the user. But when using the FUIPhoneAuth this does not seem possible. *How do I get hold of the FIRAuthCredential in order to deregister a user?*
-
可以重复使用"FIRAuthCredential ",还是需要先通过SMS进行完整的重新认证,然后用户才能 删除了吗?
Can one reuse the "FIRAuthCredential or does one need to do a complete re-authentication with a SMS before the user can be deleted?
使用 FUIPhoneAuth 注册后,如何注销用户?
How does one deregister a user when registered using FUIPhoneAuth?
推荐答案
按照常规重新进行身份验证,然后调用deleteWithCompletion. 由于您已经有了单元号,因此无需重新捕获.
Re-Authenticate as per normal and then call deleteWithCompletion. Since you already have the cell number, you do not need to recapture that.
FIRAuth *auth = [(AppDelegate*)[UIApplication sharedApplication].delegate auth];
FIRPhoneAuthProvider *provider = [FIRPhoneAuthProvider providerWithAuth:auth];
[provider verifyPhoneNumber:user.phoneNumber
UIDelegate:nil
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
if (error) {
return;
}
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Verification"
message:@"Enter the SMS verfication code" preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"SMS Code";
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSArray *textfields = alert.textFields;
UITextField *codeField = textfields[0];
FIRAuthCredential *credential = [provider credentialWithVerificationID:verificationID verificationCode:codeField.text];
[user reauthenticateWithCredential:credential completion:^(NSError * _Nullable error) {
// unregister
[user deleteWithCompletion:^(NSError * _Nullable error) {
if (error) {
NSLog(@"FIR: User delete failed: %@",error.localizedDescription);
}
NSLog(@"FIR: User Deleted success");
}];
}];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler: ^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}];
这篇关于使用Phone Auth注册时如何注销/注销Firebase用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!