title: Nest JS Guards - Use one of two strategies
body: <p>My app has two JWT based strategies:</p>
  <ul>
  <li>Single sign on for my organization and its members. An external provider creates a JWT for this case.</li>
  <li>Email/Password authenticated external users. My app creates a JWT for this case.</li>
  </ul>
  <p>On any given route, I only need one of these to succeed to allow access. The problem is that if multiple guards are declared, then ALL guards must succeed.</p>
  <p>For example, this would require both guards to succeed, but only one will ever succeed.</p>
  <pre><code>@UseGuards(AuthGuard('local-jwt'))
  @UseGuards(AuthGuard('azure-ad'))
  someRoute(
    @CurrentUser currentUser: User,
  ) {
    //...
  }
  </code></pre>
  <hr />
  <p>On <a href="https://github.com/nestjs/nest/issues/873" rel="nofollow noreferrer">this issue</a>, I found this snippet:</p>
  <pre><code>@Injectable()
  export class ComposeGuard implements CanActivate {
    constructor(private allowGuard: AllowGuard, private authGuard: AuthGuard, private roleGuard: RoleGuard) {
    }
  
    async canActivate(context: ExecutionContext): Promise&lt;boolean&gt; {
      return await this.allowGuard.canActivate(context) || (await this.authGuard.canActivate(context) &amp;&amp;  await this.roleGuard.canActivate(context));
    }
  }
  </code></pre>
  <p>This seems to allow the custom logic I need, but I have no idea how to import the guards as dependencies. A guard does not seem to be a class, so it's valid for dependency injection. And a strategy is a class, but does not have a <code>canActivate</code> method.</p>
  <hr />
  <p>The other option I found was to <a href="https://github.com/nestjs/nest/issues/873#issuecomment-470173780" rel="nofollow noreferrer">make one strategy inherit from the other</a>. But that's an ugly semantic mess since they are parallel, and do not depend on one another at all.</p>