ReferenceError: For request with hapi/Node.js
ReferenceError: For request with hapi/Node.js
我有这两个 api 处理程序:
module.exports.loginWeb = function (request, reply, next) {
if (request.auth.isAuthenticated) {
return reply.redirect('/');
}
if(request.method === 'get'){
reply.view("account/login", { title: 'Login' }, {layout: 'account'});
}else{
console.log(request);
login(request, reply, next, 'web');
}
};
module.exports.registerWeb = function(request, reply, next) {
if (request.auth.isAuthenticated) {
return reply.redirect('/');
}
if(request.method === 'get'){
reply.view("account/register", { title: 'Register' }, {layout: 'account'});
}else{
// checkbox1 name should be changed
if (!request.payload.checkbox1){
return reply('Please accept Terms & Conditions')
}
register(request, reply, next, 'web');
}
};
注册处理程序工作正常,但登录处理程序出现错误,ReferenceError:未捕获错误:未定义请求。
但是请求正在该行上方成功打印。可能是什么问题呢?另外正如我所说,注册处理程序可以正常使用相同类型的代码。
编辑:添加登录功能
function login(register, reply, next, flag){
if (!request.payload.email || !request.payload.password){
return reply('Please enter email and password');
}
Account.findOne({email: request.payload.email[0]}, function(err, user){
if (err){
return reply(err)
}
else {
if (!user){
return reply('user doesnt exists')
}
else {
//doing bunch of stuff
}
}
})
}
问题出在 login
函数中 - request
未定义为该函数的参数。也许你打算写:
login(request, ...
你在哪里
login(register, ...
我有这两个 api 处理程序:
module.exports.loginWeb = function (request, reply, next) {
if (request.auth.isAuthenticated) {
return reply.redirect('/');
}
if(request.method === 'get'){
reply.view("account/login", { title: 'Login' }, {layout: 'account'});
}else{
console.log(request);
login(request, reply, next, 'web');
}
};
module.exports.registerWeb = function(request, reply, next) {
if (request.auth.isAuthenticated) {
return reply.redirect('/');
}
if(request.method === 'get'){
reply.view("account/register", { title: 'Register' }, {layout: 'account'});
}else{
// checkbox1 name should be changed
if (!request.payload.checkbox1){
return reply('Please accept Terms & Conditions')
}
register(request, reply, next, 'web');
}
};
注册处理程序工作正常,但登录处理程序出现错误,ReferenceError:未捕获错误:未定义请求。
但是请求正在该行上方成功打印。可能是什么问题呢?另外正如我所说,注册处理程序可以正常使用相同类型的代码。
编辑:添加登录功能
function login(register, reply, next, flag){
if (!request.payload.email || !request.payload.password){
return reply('Please enter email and password');
}
Account.findOne({email: request.payload.email[0]}, function(err, user){
if (err){
return reply(err)
}
else {
if (!user){
return reply('user doesnt exists')
}
else {
//doing bunch of stuff
}
}
})
}
问题出在 login
函数中 - request
未定义为该函数的参数。也许你打算写:
login(request, ...
你在哪里
login(register, ...