I specify guards for JWT
and SSO
in my Nest.js api, but now that the project gets larger some specific resolvers need to be accesable by both auth strategies.
I've created a ChainGuard
which loops through the guards:
@Injectable()
export class ChainGuard extends AuthGuard(['jwt', 'sso']) {...}
Now I want to use it in one of my resolvers as this:
import { Controller, Get, UseGuards } from '@nestjs/common';
import { JWTGuard } from './jwt.guard';
import { ChainGuard } from './chain.guard';
@Controller('users')
@UseGuards(JWTGuard)
export class UsersController {
@Get()
getUsers() {
// Return list of users
}
@Get(':id')
@UseGuards(ChainGuard)
getUser(@Param('id') id: string) {
// Return user details for the given ID
}
}
This doesn't seem to work as I can't bypass the class guard JWTGuard
After researching a bit, most people recommend setting metadata
for that specific resolver if you are trying to bypass the WHOLE authentication (e.g. public endpoint).
But I'm not trying to do that, I just want to use a different guard while keeping the same old guard for the other resolvers in that Class.
Is something like this possible?