0
  @ApiBasicAuth()
  @UseGuards(LocalAuthGuard)
  @Post('login')
  async login(@Request() req) {
    return this.authService.login(req.user);
  }

When I open up the api docs, the auth for this route shows a "username" and a "password" field. I want to change the username field to "email". Is that possible?

Bousha
  • 11
  • 1
  • 3

2 Answers2

1

Note that this has nothing with @nestjs/swagger. You need to pass configuration to passportjs in your class LocalStrategy provider, like this:

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
  constructor(private authService: AuthService) {
    super({ usernameField: 'email' })
  }
  ...
}

As the docs states here: https://docs.nestjs.com/security/authentication#implementing-passport-local

please read the entire Nestjs's docs, it is pretty good :)

Micael Levi
  • 5,054
  • 2
  • 16
  • 27
  • Thank you for your reply. The code block you mentioned is already implemented in my code and works as intended. My problem is that the Swagger api doc doesn't reflect this properly – Bousha Mar 22 '21 at 17:09
0

Show us how you're define the body schema for this endpoint. @nestjs/passport will not define this for you.

You could add the decorator @ApiBody({ type: LoginDto }) in your login method

class LoginDto {
  email: string
  password: string
}
Micael Levi
  • 5,054
  • 2
  • 16
  • 27