以下代码中导致错误的问题是什么? 在编写函数之前应该先写let还是function关键字?
module.exports = {
postLogin=(req, res, next) => {
const { mobile, password } = req.body;
User.findByCredentials(mobile, password).then((user) => {
return user.generateAuthToken().then((token) => {
res.header('x-auth', token).send(user);
});
}).catch((e) => {
res.status(400).send();
});
}
getMe=(req, res, next) => {
res.send(req.user);
}
getLogout=(req, res, next) => {
req.user.removeToken(req.token).then(() => {
res.status(200).send();
}, () => {
res.status(400).send();
});
}
}
答案 0 :(得分:0)
正确的是:
module.exports = {
postLogin: (req, res, next) => {
const { mobile, password } = req.body;
User.findByCredentials(mobile, password).then((user) => {
return user.generateAuthToken().then((token) => {
res.header('x-auth', token).send(user);
});
}).catch((e) => {
res.status(400).send();
});
},
getMe: (req, res, next) => {
res.send(req.user);
},
getLogout: (req, res, next) => {
req.user.removeToken(req.token).then(() => {
res.status(200).send();
}, () => {
res.status(400).send();
});
} }