Skip to content

FST_ERR_DEC_ALREADY_PRESENT: The decorator 'xxx' has already been added! #2115

@wiredmartian

Description

@wiredmartian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions