为什么我收不到电话号码?

问题描述 投票:0回答:1

我想用电话号码登录,但我在 Nestjs 上没有得到电话号码。

当我发送此信息时: 一切都好。

但是如果我发送这个: 我无法登录。

所以我在构造函数中添加了 usernameField: 'email'、phoneField: 'phoneNumber',用于检查,但它不起作用。
在 webstorm 中我写了 console.log(

 pass ${password}
) 我看到:

本地策略:

    @Injectable()
    
    export class LocalStrategy extends PassportStrategy(Strategy) {
    
      constructor(private authService: AuthService) {
        super({
          usernameField: 'email',
          phoneField: 'phoneNumber',
        });
      }
    
      async validate(
        email: string,
        password: string,
        phoneNumber: string,
      ): Promise<any> {
    
        console.log(` mail ${email}`)
        console.log(` pass ${password}`)
        console.log(` phone ${phoneNumber}`)
    
        const user = await this.authService.validateUser(
          email,
          password,
          phoneNumber,
        );
        // console.log(user)
    
        if (!user) {
          throw new UnauthorizedException('Неверный логин или пароль');
        }
    
        return user;
      }
    }
node.js nest backand
1个回答
0
投票

我已经做到了。

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {

  constructor(
    private authService: AuthService,
    private moduleRef: ModuleRef
  ) {
    super({
      passReqToCallback: true,
      usernameField: 'email',
      phoneNumber: 'phoneNumber',
      passwordField: 'password',
    });
  }

  async validate(
    request: Request,
    email: string,
    phoneNumber: string,
    password: string,
  ): Promise<any> {

    const contextId = ContextIdFactory.getByRequest(request);

    const flex = await this.moduleRef.resolve(AuthService, contextId);

    const user = await this.authService.validateUser(
      request.body,
      email,
      phoneNumber,
      password,
    );
    console.log(user)

    if (!user) {
      throw new UnauthorizedException('Неверный логин или пароль');
    }

    return user;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.