@UseGuards(JwtAccessTokenAuthGuard)
@ApiBearerAuth()
@SetMetadata('roles', Role.ADMIN)
@UseGuards(RolesGuard)
@Post('/add/card')
addCard(@Body() addCardDto: AddCardDto) {
return this.storeService.addCard(addCardDto);
}
This is the RoleGuard
canActivate(context: ExecutionContext): boolean {
const roles = this.reflector.get<string[]>('roles', context.getHandler());
if (!roles) {
return true;
}
const user = context.switchToHttp().getRequest().user;
return this.matchRoles(roles, user.user_type);
}
In this, the request object has user in the body or inside the function addCard but not in the RoleGuard. Their it says undefined. Why so? In the JwtAccessTokenGuard I returned the user property.
I want to check it inside the Guard and not in function. What am I doing wrong.