Skip to content

Extended passport local strategy typings not working properly #1857

Description

@joaotonaco

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I'm using the local strategy with phone field instead of username, so I need to set the usernameField to phone at the super call:

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly authService: AuthService) {
    super({ usernameField: "phone" }); 
  }

  async validate(phone: string, password: string) {
    const user = await this.authService.validateUser(phone, password);
    return user;
  }
}

But by doing this, typescript yells at me that super() does not receive any arguments. But if I remove it the authentication fails.

Minimum reproduction code

N/A

Steps to reproduce

N/A

Expected behavior

Proper typings.

Package version

11.0.2

Passport version

passport-jwt 4.0.1; passport-local 1.0.0

NestJS version

11.0.1

Node.js version

22.12.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Am I doing it right? Should I just use @ts-ignore?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions