I'm trying to decorate a request with the current user's data from the jwt auth token;
server.addHook("preHandler", async (request, reply, done) => {
let { userId, email } = await request.jwtVerify();
userId = AESEncryption.decrypt(userId);
server.decorateRequest("currentUser", {
userId: userId,
email: email
});
done();
});
PROBLEM
The first request GET works, but when I make the same request again, I get this error:
{
"statusCode": 500,
"code": "FST_ERR_DEC_ALREADY_PRESENT",
"error": "Internal Server Error",
"message": "FST_ERR_DEC_ALREADY_PRESENT: The decorator 'currentUser' has already been added!"
}
Environments
node version: 11.15
fastify version: 2.11
os: Linux
I'm trying to decorate a request with the current user's data from the jwt auth token;
PROBLEM
The first request
GETworks, but when I make the same request again, I get this error:Environments
node version: 11.15
fastify version: 2.11
os: Linux