#Decorators: Declaration expected

7 messages · Page 1 of 1 (latest)

steep lily
#
@Auth()
app.get("/generate-password", {
  handler: async(request: FastifyRequest, reply: FastifyReply) => {
    const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*,-./:;<>=?@[]^_~+";
    let password = "";
    for (let i = 0; i < 16; i++) {
      password += characters.charAt(Math.floor(Math.random() * characters.length));
    }

    reply.send({ password });
  }
});

Error: Parsing error: Declaration expected

Decorator:

export const Auth = (type?: string) => {
  return async(request: FastifyRequest, reply: FastifyReply) => {
    console.log(type);
  };
};
hollow orchid
#

you can't decorate function calls

#

only classes, or methods, or properties

#

maybe some other stuff too but i'm not sure what

steep lily
#

Is there an alternative to what I want to do? or a solution?

hollow orchid
#

well

#

what is type supposed to be