繁体   English   中英

如何删除流星中的登录用户

[英]How to remove logged in user in Meteor

我正在Meteor中开发一个应用程序,我想知道该怎么做才能删除登录系统的用户帐户? 我的意思是,您可以删除您的帐户(例如Tinder或Facebook),并且该应用程序会弹出您的帐户,因为您已经被删除,并且不再存在。

附带一个简单的按钮“删除您的帐户”。

在此处输入图片说明

如果你能帮助我; 我仍然是一个新手,我将非常感激它,我尝试使用Meteor.userId()检索当前用户的ID,并以以下方式创建方法:

Meteor.methods({
  SuprimirPersona: function(id) {
    var postId = Meteor.userId();
    const userId = this.userId;
    const p = Meteor.users.findOne(postId);
    if (userId && p === userId) {
      Meteor.users.remove({
          postId: this._id
        },
        function(error, result) {
          if (error) {
            console.log("Error removing user:", error);
          } else {
            console.log("users removed:" + result);
          }
        })
    }
  }
});

并以以下方式调用该方法,但未给出任何结果,我不明白为什么:

'click #Desactivarr': function() {
  var postId = Meteor.userId();
  Meteor.call('SuprimirPersona', userId, function(error, result) {
    if (error) {
      console.log("Somee Error");
    }
  });
  Meteor.logout(function() {
    FlowRouter.go('/');
  });
},

希望有人可以帮助我! 问候!

从用户的集合中删除用户。 您需要获取要删除的用户的用户标识。 您可以通过在客户端上调用Meteor.userId()来获取用户的用户ID或服务器上的this.userId来获得此功能。 您需要注销用户,成功注销后,您可以将获得的用户标识传递给meteor.users.remove(userId)

您正在客户端和服务器端执行一些不必要的操作-例如多次获取相同的用户ID,甚至没有将其传递给服务器端方法,然后再次获取它。

我认为您想要做的是获取发布了内容的用户的ID,并将其传递给服务器端,在服务器端您检查发布者的ID是否与当前用户的ID相同。 如果是这样,则删除该用户,否则什么也不会发生。

'click #desactivarr' : function() {
  var postID = <get the id of the user you want to delete here>;
  Meteor.call("suprimirPersona", postID, callbackfunc);
}

然后在服务器端

Meteor.methods({
  suprimirPersona : function(postID) {
    var userID = Meteor.userId();
    if (userID && postID === userID) {
      Meteor.users.remove({ postId : userID })
    }
  }
});

Meteor.userId()和this.userId返回正在客户端执行代码或向服务器端方法发出请求的当前登录用户的ID。

我刚刚在流星论坛上回答了这个问题: https : //forums.meteor.com/t/how-to-remove-logged-in-user-in-meteor/42639/3

问题是您正在尝试通过postId而不是Users.remove({_ id:id})删除用户。 您什么都没删除:)

暂无
暂无

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

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