我怎么能通过2个以上的字段作为用户名在这种情况下?我想做的电话号码和SSA登录不仅与电子邮件。
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private authenticationService: AuthenticationService) {
super({
usernameField: 'email'
});
}
async validate(email: string, password: string) {
return this.authenticationService.getAuthenticatedUser(email, password);
}
}
2条答案
按热度按时间n7taea2i1#
你可以在构造函数中将passReqToCallback选项传递给你的
super()
调用,这将为我们的validate函数提供完整的req
对象作为第一个参数,这样我们就可以随意使用它,如下所示:我把这个问题作为参考,它应该同样适用于nestjs/passport库。Using PassportJS, how does one pass additional form fields to the local authentication strategy?
irtuqstp2#
试试这个。
我查找了有关是否可以添加新字段的信息,但在文档和论坛中没有找到任何内容