我正在使用Firebase和android studio。并且我尝试删除用户时出现问题。电话号码验证是访问我的应用程序的唯一方法。
我已经知道删除用户时必须重新进行身份验证。 因此,我参考了Firebase文档并进行了尝试。尽管我只有PhoneNumber和UID,但AuthCredential.getCredential()方法需要几个值。 这就是我所知道的
这是代码
AuthCredential credential = PhoneAuthProvider
.getCredential(user.getUid(), null);
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
//재인증 성공시
@Override
public void onComplete(@NonNull Task<Void> task) {
//삭제
user.delete()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d("result", "User account deleted.");
}else{
Log.d("", task.getException().getStackTrace().toString());
}
}
});
}
});
这是例外 :
java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, ortemprary proof.
at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source)
at com.google.firebase.auth.PhoneAuthCredential.<init>(Unknown Source)
at com.google.firebase.auth.PhoneAuthProvider.getCredential(Unknown Source)
at com.dataflow.deliverytalk.Activities.popup.LogoutPopupActivity$1$override.onClick(LogoutPopupActivity.java:58)
at com.dataflow.deliverytalk.Activities.popup.LogoutPopupActivity$1$override.access$dispatch(LogoutPopupActivity.java)
at com.dataflow.deliverytalk.Activities.popup.LogoutPopupActivity$1.onClick(LogoutPopupActivity.java)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
答案 0 :(得分:1)
显然,您也可以使用云功能删除用户,而无需重新验证用户,而只需提供uid。这是
exports.deleteUser = functions.https.onRequest((req, res) => {
if (req.body.uid === undefined) {
res.status(400).send('No user id defined');
} else {
var userId = req.body.uid;
admin.auth().deleteUser(userId)
.then(function() {
console.log("Successfully deleted user");
})
.catch(function(error) {
console.log("Error deleting user: ", error);
});
res.status(200).end();
}
});
更多info