All files / events OnConfirmPassword.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  3x   3x                 3x       3x 3x 3x 3x 1x     2x   2x     1x       3x  
import { IAuthenticationResult } from '../types';
import { Auth } from 'aws-amplify';
import _ from 'lodash';
import OnCheckSession from './OnCheckSession';
 
/**
 * Confirm change password flow started by {@link OnForgotPassword}
 * @param code user code used to confirm account
 * @param userName the user to confirm
 * @param newPassword the new password for user
 * @returns See {@link IAuthenticationResult}
 */
export const OnConfirmPassword = async (
  code: string,
  userName: string,
  newPassword: string
): Promise<IAuthenticationResult> => {
  try {
    const codeInt = Number(code);
    if (!codeInt || codeInt < 100) {
      throw Error('Not a valid Code');
    }
 
    await Auth.forgotPasswordSubmit(userName, codeInt.toString(), newPassword);
 
    return OnCheckSession();
  } catch (error) {
    // if (__DEV__) console.log(error);
    return OnCheckSession(error);
  }
};
 
export default OnConfirmPassword;