0
我有一個下載路線在我的MeteorJs應用程序,我想限制訪問。路由代碼如下流星JS(鐵路由器) - 限制訪問服務器路線
Router.route("/download-data", function() {
var data = Meteor.users.find({ "profile.user_type": "employee" }).fetch();
var fields = [...fields];
var title = "Employee - Users";
var file = Excel.export(title, fields, data);
var headers = {
"Content-type": "application/vnd.openxmlformats",
"Content-Disposition": "attachment; filename=" + title + ".xlsx"
};
this.response.writeHead(200, headers);
this.response.end(file, "binary");
},
{ where: "server" }
);
路由自動下載文件。這目前正在工作,但我想限制對路線的訪問。我只希望管理員能夠下載它。
我已經創建了一個onBeforeAction
掛鉤如下
Router.onBeforeAction(
function() {
//using alanning:roles
if(Roles.userIsInRole(this.userId, "admin"){
console.log('message') //testing
}
},
{
only: ["downloadData"]
}
);
,並更名爲我的路線如下
//code above
this.response.writeHead(200, headers);
this.response.end(file, "binary");
},
{ where: "server", name: "downloadData" }
);
的onBeforeAcion
鉤不採取任何影響
而且我注意到既不this.userId
也不Meteor.userId
作品的路線