作为我现在正在建立的新注册表格的一部分,我需要提取当时所有可用的“机构”的列表,以便用户可以告诉我他们要注册的机构。
在后端策略中,我将控制器操作设置为public:
InstitutionController: {
// Some other policies I edited out
'all': true
},
控制器是您的标准“获取所有对象”控制器动作。
all: function (req, res) {
Institution
.find()
.exec(function (err, institutions) {
if (err) { return res.json(err.status, err); }
return res.json(institutions);
});
},
因此,在AngularJS前端上,Institutions.all()
即使在用户登录之前,我也应该能够在控制器中使用。确实是这种情况,但是在后端passport
,尝试在执行之前对(不存在的)用户进行序列化和反序列化这种方法。
因此,我在API控制台收到了此错误消息:
error: Server Error:
error: Error: Failed to deserialize user out of session
at pass (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:340:19)
at deserialized (/home/zacharyhustles/texasca-API/node_modules/passport/lib/authenticator.js:345:7)
at bound (/home/zacharyhustles/texasca-API/node_modules/lodash/dist/lodash.js:957:21)
.......
尝试执行此控制器方法时,如何避免对用户进行护照序列化和反序列化InstitutionController.all()
?
更新
问题在于此请求正在发送,withCredentials: true
因为我的带有restangular的HTTP字段的默认设置true
在我的应用程序app.js
文件中设置为:
app.js
RestangularProvider.setDefaultHttpFields({ withCredentials: true });
如果我将其设置为“ false”,则问题得到解决。但是,我确实希望将对服务器的大多数请求发送给“ withCredentials”,因此我需要一种方法来对此请求进行例外处理。如您所见,我在应用程序中使用Restangular,因此希望可以以Restangular的方式进行操作。有谁知道如何做到这一点?
最好的,扎克
我想到了。
Restangular添加了一种设置每个请求的自定义http字段的方法。我已经withCredentials : false
为此请求手动设置了。我修改后的后端调用现在看起来像这样:
return Restangular.all('institutions')
.withHttpConfig({ withCredentials: false}).getList();
以前是。
return Restangular.all('institutions').getList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句