这是我的代码
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,
});
});
},
//change whoami to look like this
whoami(req, res) {
authService
.whoami(req) //req instead of only request body
.then((user) => {
res.status(200).json(user);
})
.catch((err) => {
console.log(err);
res.status(422).json({
status: "FAIL",
message: err.message,
});
});
},