引入jwt
const jwt = require('jsonwebtoken')
登录接口
router.post("/login",async(req,res)=>{
let body=req.body
console.log(body);
let user=await userModel.find({username:body.username})
console.log(user);
if(user[0]){
if(user[0].password==body.password){
let token='Bearer'+''+jwt.sign(body,'lec',{expiresIn:"1h"})
res.send({
code:200,
msg:"已登录",
token
})
}else{
res.send({
code:400,
msg:"密码错误",
})
}
}else{
res.send({
code:400,
msg:"用户不存在",
})
}
})