title: Is it possible to have multiple local strategies in passport implemented with NestJS
body: <p>I have a scenario where I need to implement an authentication mechanism for admin and for normal users in my application using the Passport local strategy. I implemented the strategy for the normal users as described <a href="https://docs.nestjs.com/security/authentication#implementing-passport-strategies" rel="nofollow noreferrer">here</a>. It is working perfectly fine.</p>
  <p>However, now I need to implement the same local strategy for Admin login. I feel like it would have been much easier if both the type of users(admin and normal user) are on the same entity/table because a single validate function would be capable enough to handle the case but my application design has separate entities for Admins and normal users and hence are the separate services.</p>
  <p>My local strategy looks something like this:</p>
  <pre><code>@Injectable()
  export class LocalStrategy extends PassportStrategy(Strategy) {
      constructor(private userService: UserService) {
          super();
      }
  
      async validate(username: string, password: string): Promise&lt;any&gt; {
          const user = await this.userService.validateUser(username, password);
          if (!user) {
              throw new UnauthorizedException(&quot;Incorrect credentials!&quot;);
          }
          return user;
      }
  }
  </code></pre>
  <p>As I went through the documentation, it is said that a Local Strategy can have only one validate function(that works as a verify callback), if this is the case how do I differentiate a logic inside this single validate function to behave differently for the requests coming in from the normal user controller and from the admin controller? Because in the admin login case, I'll be using a different route something like(admin/login), and for the user, it could be something like(user/login).</p>
  <p>What's the best approach for this? Do I need to create a separate local strategy for admin? If yes, any hints will be appreciated. Otherwise, how can I incorporate logic inside this single validate function?</p>
  <p>One of the alternatives could be checking if data exists in both the tables for every login payload each time. This approach doesn't look quite right to me.</p>
  <p>If this provides more insight, the auth guard is simple as this:</p>
  <pre><code>@Injectable()
  export class LocalAuthGuard extends AuthGuard('local') { 
  }
  </code></pre>