Secure meteor admin functionality

梦想的初衷 提交于 2019-12-24 16:03:20

问题


I have a couple of admin functions I want to add to a meteor site and was wandering what is the best way to create, hide and protect them ?

Thanks


回答1:


You can use Meteor.methods. Just be sure to only include them on the server, by placing the code in a folder called server/ E.g.

server/admin.js

Meteor.methods({
  foo: function (arg1, arg2) {
    // confirm that the user is an admin
    if ( ! this.user.isAdmin )
      throw new Meteor.Error(401, "You are not authorized to perform this action");
    // perform task
    return "some return value";
  }
});


来源:https://stackoverflow.com/questions/14666232/secure-meteor-admin-functionality

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!