【问题标题】:How use more than one field in my passport strategy如何在我的护照策略中使用多个字段
【发布时间】:2021-05-12 02:10:09
【问题描述】:

在这种情况下,如何将另外 2 个字段作为用户名传递?我想通过 phone_number 和 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);
    }
}

【问题讨论】:

标签: node.js express passport.js nestjs passport-local


【解决方案1】:

试试这个。

export class LocalStrategy extends PassportStrategy(Strategy) {
    constructor(private authenticationService: AuthenticationService) {
        super({
            usernameField: 'phone_number'
        });
    }
    async validate(phone_number: string, password: string) {
        return this.authenticationService.getAuthenticatedUser(phone_number, password);
    }
}

我查找是否可以添加新字段的信息,但在文档和论坛中没有找到任何信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 2021-02-11
    • 2015-11-14
    • 2021-10-26
    • 1970-01-01
    • 2019-05-09
    • 2019-04-20
    相关资源
    最近更新 更多