简体   繁体   English

Angular + Firebase在注销时删除用户

[英]Angular + Firebase Delete user on logout

I'm developing and application using angular 4 and firebase. 我正在使用angular 4和firebase开发和应用。 In this I'm giving access to the user with a login (email and password) and as guest (using anonymous auth), but I want to delete the user if the user is a guest (anonymous auth user) when he logs out of the application. 在这种情况下,我以登录名(电子邮件和密码)和访客身份(使用匿名身份验证)授予用户访问权限,但是如果用户是访客身份(匿名身份验证用户),则我想删除该用户应用程序。

How can I delete a user from firebase auth, not from the realtime database or the firestore database, from the auth section of firebase? 如何从firebase的auth部分中,从firebase auth中删除用户,而不是从实时数据库或firestore数据库中删除用户?

One option is to create two logout button and show using *ngIf . 一种选择是创建两个注销按钮,并使用*ngIf显示。 If user is logged in as anonymous you need to perform delete user rather than logout. 如果用户以匿名身份登录,则需要执行删除用户而不是注销。

var user = firebase.auth().currentUser;

user.delete().then(function() {
  // User deleted. Redirect to login page...
}).catch(function(error) {
  // An error happened.
});

Or you can first do a check inside your logout function and proceed user.isAnonymous 或者您可以先在注销功能中进行检查并继续执行user.isAnonymous

logout(){
    var user = firebase.auth().currentUser;
    if(user.isAnonymous){
        user.delete().then(function() {
          // User deleted. Redirect to login page...
        }).catch(function(error) {
          // An error happened.
        });
    }else{
        //perform logout
    }
}

check this doc for more info 检查此文档以获取更多信息

( i didn't tested code myself. ) 我自己没有测试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM