Reputation: 11
@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?
Upvotes: 0
Views: 1866
Reputation: 6685
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
}
Upvotes: 0
Reputation: 6685
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 :)
Upvotes: 1