这是我的密码
const bcrypt = require("bcryptjs");
const jwt = require("jsonwebtoken");
const userRepository = require("../repositories/userRepository");
const SALT = 10;
async whoami(req, next) {
const bearerToken = req.headers.authorization;
const token = bearerToken.split("Bearer ")[1];
const tokenPayload = jwt.verify(token, process.env.JWT_SIGNATURE_KEY || "Rahasia");
req.user = await userRepository.find(tokenPayload.id);
next();
},
这是控制器
whoami(req, res) {
authService
.whoami(req.body)
.then((user) => {
res.status(200).json(user);
})
.catch((err) => {
console.log(err);
res.status(422).json({
status: "FAIL",
message: err.message,
});
});
},
1条答案
按热度按时间xlpyo6sf1#