我有一个使用firebase
的sails.js
项目,登录后我无法将user
数据保存在session
中,我已经尝试了很多次但没有奏效。
这是我的action fn
:
fn: async function (inputs) {
var _res = this.res;
var _req = this.req;
var _session = this.req.session;
firebase.auth().signInWithEmailAndPassword(inputs.emailAddress, inputs.password)
.then((data) => {
console.log(data.user.uid);
_session.userId = data.user.uid;
return _res.json(data.user);
})
.catch((error) => {
console.log('Error => ', error);
// return _res.redirect('back');
});
}
使用return _res.json()
时,它会给我这个错误
Error => Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:485:11)
所以我想要的只是在登录后将用户数据保存在会话中。
我相信您没有将await
用于signinwithemailandpassword
.此外,你为什么要在后端这样做?它专为前端使用而设计。