routes/apiHandlers.js
/**
 * Verify the SMS code and then ask the gatekeeper for the status of the account
 * do decide the next step
 */
Verify the SMS code and then ask the gatekeeper for the status of the account
do decide the next step
Verify the SMS code and then ask the gatekeeper for the status of the account do decide the next step
async function handleConfirmSms(req) {
    const decoded = verifyToken(req.body.token, 'signup');
    if (!req.body.code) {
        throw new ApiError({
            field: 'code',
            type: 'error_api_code_required',
        });
    }
    const user = await database.findUser({
        where: { email: decoded.email },
    });
    if (!user) {
        throw new ApiError({
            field: 'code',
            type: 'error_api_unknown_user',
        });
    }
    if (user.phone_number_is_verified) {
        throw new ApiError({
            field: 'code',
            type: 'error_api_phone_verified',
        });
    }
    if (user.phone_code_attempts >= 5) {
        throw new ApiError({
            field: 'code',
            type: 'error_api_phone_too_many',
        });
    }
    user.phone_code_attempts = (user.phone_code_attempts || 0) + 1;
    if (user.phone_code !== req.body.code) {
        await user.save();
        throw new ApiError({
            field: 'code',
            type: 'error_api_code_invalid',
        });
    }
    user.phone_number_is_verified = true;
    await user.save();
    const completed = await finalizeSignup(user, req);
    return { success: true, completed };
}
async function handleConfirmSms ( req ) { const decoded = verifyToken ( req . body . token , 'signup' ) ; if ( ! req . body . code ) { throw new ApiError ( { field : 'code' , type : 'error_api_code_required' , } ) ; } const user = await database . findUser ( { where : { email : decoded . email } , } ) ; if ( ! user ) { throw new ApiError ( { field : 'code' , type : 'error_api_unknown_user' , } ) ; } if ( user . phone_number_is_verified ) { throw new ApiError ( { field : 'code' , type : 'error_api_phone_verified' , } ) ; } if ( user . phone_code_attempts >= 5 ) { throw new ApiError ( { field : 'code' , type : 'error_api_phone_too_many' , } ) ; } user . phone_code_attempts = ( user . phone_code_attempts || 0 ) + 1 ; if ( user . phone_code !== req . body . code ) { await user . save ( ) ; throw new ApiError ( { field : 'code' , type : 'error_api_code_invalid' , } ) ; } user . phone_number_is_verified = true ; await user . save ( ) ; const completed = await finalizeSignup ( user , req ) ; return { success : true , completed } ; }
Verify the SMS code and then ask the gatekeeper for the status of the account
 do decide the next step
Verify the SMS code and then ask the gatekeeper for the status of the account do decide the next step