結論
passport-localはデフォルトでは以下のプロパティ名を持つデータしか受け取ることができません!
- username
- password
悪い例
{
"email": "user@example.com",
"password": "hogefuga"
}
良い例
{
"username": "user@example.com", // ← usernameを使う
"password": "hogefuga"
}
カスタマイズもできる
プロパティ名をusername
以外にしたい時はusernameField
オプションで明示的に指定する必要があります。
NestJSの場合は以下のように変更します。
NestJSでの例
...
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super({ usernameField: 'email' }); // ←emailを使いたい場合
}
...
このことを知らず半日を費やしてしまったため戒めの意味で記事を書きました😅