i want to use async await in middleware
but when i use my code this error occure
const refrsh = await User.findOne({ ^^^^^ SyntaxError: await is only valid in async function
how can i fix my code?
this is my code
exports.authenticateToken = (req, res, next) => {
const authHeader = req.headers["authorization"];
const token = authHeader && authHeader.split(" ")[1];
if (token == null) return res.sendStatus(401);
jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
if (err) {
const refreshToken = req.body.refreshToken;
const refrsh = await User.findOne({
where: {id:req.body.kakaoid}
})
}
req.user = user;
next();
});
};