Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async authenticate(params: PasswordLoginType): Promise {
const { user, password, code } = params;
if (!user || !password) {
throw new Error(this.options.errors.unrecognizedOptionsForLogin);
}
if ((!isString(user) && !isPlainObject(user)) || !isString(password)) {
throw new Error(this.options.errors.matchFailed);
}
const foundUser = await this.passwordAuthenticator(user, password);
// If user activated two factor authentication try with the code
if (getUserTwoFactorService(foundUser)) {
await this.twoFactor.authenticate(foundUser, code!);
}
return foundUser;
}
constructor(options: AccountsPasswordOptions = {}) {
this.options = { ...defaultOptions, ...options };
this.twoFactor = new TwoFactor(options.twoFactor);
}