All files OnConfirmAccount.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  3x   3x               3x     2x 2x 2x 2x 1x     1x   1x     1x       3x  
import { IAuthenticationResult } from '../types';
import { Auth } from 'aws-amplify';
import _ from 'lodash';
import OnCheckSession from './OnCheckSession';
 
/**
 * Handles confirm Cognito confirm account event
 * @param code user code used to confirm account
 * @param userName the user to confirm
 * @returns See {@link IAuthenticationResult}
 */
export const OnConfirmAccount = async (
  code: string,
  userName: string
): Promise<IAuthenticationResult> => {
  try {
    const codeInt = Number(code);
    if (!codeInt || codeInt < 100) {
      throw Error('Not a valid Code');
    }
 
    await Auth.confirmSignUp(userName, codeInt.toString(), undefined);
 
    return OnCheckSession();
  } catch (error) {
    // if (__DEV__) console.log(error);
    return OnCheckSession(error);
  }
};
 
export default OnConfirmAccount;