postman不管什么用户都是返回登陆失败
来源:6-9 API对接mysql(登录)
gakaika
2021-04-11
controller
const { exec } = require(’…/db/mysql’)
const loginCheck = (username, password) => {
const sql = select username, realname from users where username='${username}' and password='${password};'
return exec(sql).then(rows => {
return rows[0] || {}
})
}
module.exports = {
loginCheck
}
router
const { loginCheck } = require(’…/controller/user’)
const { SuccessModel, ErrorModel } = require(’…/model/resModel’)
const handleUserRouter = (req, res) => {
const method = req.method //GET POST
//登陆
if (method === 'POST' && req.path === '/api/user/login') {
const { username, password } = req.body
const result = loginCheck(username, password)
return result.then(data => {
if (data.username) {
return new SuccessModel()
}
return new ErrorModel('登陆失败')
})
}
}
module.exports = handleUserRouter
不管用户名密码是否正确,都返回的登录失败,不知到底是哪里的原因
写回答
1回答
-
双越
2021-04-11
返回登录失败,那肯定是 data.username 为空,那它为何为是空呢?打印一下 dat 是什么?……
顺着代码逻辑调试一下即可。很快你就能发现问题。
00
相似问题