NestJS · Middle · Question 4 of 75

How does a roles guard read roles declared on a route?

export const Roles = Reflector.createDecorator<string[]>();

@Roles(["admin"])
@Delete(":id")
remove() {}

Explanation

getAllAndOverride lets a method-level value override a class-level one; getAllAndMerge combines them.

Further reading

Problem with a question

NestJS · Middle · question 4

Test yourself

Take the NestJS · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz