我正在記錄我的服務(wù)器,在登錄方法中它中斷了,告訴我在發(fā)送標(biāo)頭后我無法設(shè)置標(biāo)頭。但是目的只是返回一個json。謝謝。這是我的代碼,我正在使用bcrypt來設(shè)置更安全的用戶密碼。function login(req,res,next){if(req.headers.email && req.headers.password){ if(req.headers.email.indexOf('@')>=0 || req.headers.password.length>0){ var emailz = req.headers.email; var passwordz = req.headers.password; user.findOne({email:emailz}).then(result=>{ console.log(result); if(!result){ return res.status(401).send({error:'userDoesNotExists'}); } bcrypt.compare(passwordz,result.password,function(err,same){ if(!same){ return res.status(401).send({error:'PasswordIsNotCorrect'}); } var utente = {id: result.id, username:result.username, email:result.email, name:result.name, surname:result.surname}; console.log('Token',jwt.encode(utente,config.TOKEN_SECRET,'HS256')); next(); return res.status(200).redirect('/'); }) }) }}return res.status(401).send({error:'EmailOrPasswordAreEmpty'});}
在發(fā)送完頭文件后,無法在res.send()中設(shè)置頭文件
拉風(fēng)的咖菲貓
2021-04-19 21:17:30