使用流星恢复时不需要首次登录 [英] First Logging in is not required when using meteor restivus
问题描述
我正在使用流星Restivus创建Rest API.我的问题是该api不会强制我登录以发布帖子并获取 我的代码如下:
I am using meteor restivus to create a rest api. The issue I have is that the api does not force me to login to do posts and gets My code is as follows:
Articles = new Mongo.Collection('articles');
if (Meteor.isServer) {
// Global API configuration
var Api = new Restivus({
useDefaultAuth: true,
authRequired: true,
prettyJson: true,
version:'v1'
});
Api.addCollection(Articles);
}
我使用以下方法进行了POST:
I did a POST using:
curl -X POST http://localhost:3000/api/v1/articles/ -d"title = Witty Title" -d"author = Jack Rose"
curl -X POST http://localhost:3000/api/v1/articles/ -d "title=Witty Title" -d "author=Jack Rose"
然后我使用
curl -X GET http://localhost:3000/api/v1/articles/
但是在执行上述POST和GET之前,我没有收到强制我进行首次登录的错误.我的流星应用程序使用account-password和accounts-ui程序包.在执行任何POST或GET之前,必须执行什么操作才能使API强制我登录.
but I am not getting an error forcing me to first login before I can do the above POST and GET. My meteor app uses accounts-password and accounts-ui packages. What must I do to make the API to force me to login before I can do any POSTs or GETs.
推荐答案
我设法解决了这个问题. authRequired应该已经按照以下代码包含在addCollection中:
I managed to fix this. authRequired should have been included in addCollection as per the code below:
Articles = new Mongo.Collection('articles');
if (Meteor.isServer) {
// Global API configuration
var Api = new Restivus({
useDefaultAuth: true,
//authRequired: true,
prettyJson: true,
version:'v1'
});
Api.addCollection(Articles,{
routeOptions: {
authRequired: true
}
});
}
我在文档中有点白痴.不太清楚,但在文档中仍然如此.希望这对其他人有帮助!
I was a bit of an idiot as this is in the docs. Not so clear but in the docs none the less. Hope this helps someone else though!
只需添加:
登录后,按文档获取
curl H"X-Auth-Token:etttttttt-BM2DyXsTe-Gybtttttttttttttttt3Reo" -H"X-User-Id:pwfy4viiiiiiiyz3Kp" http://localhost:3000/api/v1/articles/
并执行这样的POST:
and do a POST like this:
curl -X POST -H"X-Auth-Token:etttttttt-BM2DyXsTe-Gybtttttttttttttttttt3Reo" -H"X-User-Id:pwfy4viiiiiiiyz3Kp"
curl -X POST -H "X-Auth-Token: etttttttt-BM2DyXsTe-Gybtttttttttttttttt3Reo" -H "X-User-Id: pwfy4viiiiiiiyz3Kp" http://localhost:3000/api/v1/articles/ -d "title=Witty Title" -d "author=Jack Rose"
这篇关于使用流星恢复时不需要首次登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!