• Resolved Leo.Lin

    (@bi1012037)


    JS path:/two-factor-authentication/simba-tfa/includes/tfa.js
    I made an API URL, and I can get the username after fetching.Because I will use fetch, I need to use a combination of async/await to wait for js to get the username.

    async function check_and_possibly_show_otp_field(form, only_cache_the_results) {
    
                    // If this is a "lost password" form, then exit
                    if ($(form).attr('id') === 'lostpasswordform' || $(form).attr('id') === 'resetpasswordform') return false;
    
                    var username = $(form).find(get_username_identifiers()).first().val();
                    var myreg = /^09[0-9]{8}$/;
    
                    if (myreg.test(username)){
                        const response = await fetch("api_url?user_name=" + username);
                        username = await response.text();
                    }
    if (!username.length) return false;
    ...
    }

    But using the syntax of async/await, I got Promise, which caused the following equation code to be abnormal, and the verification error will always be displayed. How can I modify the JS so that it can operate with async/await?

    Question: e.preventDefault() and return false not work!(Still run and submit)

    var form_submit_handler = function(e) {
    
                    console.log('Simba TFA: form submit request');
    
                    var form = e.target;
    
                    var form_is_gravity_forms = ('object' == typeof window['gform_gravityforms'] && 'undefined' !== typeof $(form).attr('id') && 'gform_' === $(form).attr('id').substring(0, 6));
    
                    // Turn off everything
                    $(form).off();
    
                    if (0 == $(form).find('#simba_two_factor_auth').length && check_and_possibly_show_otp_field(form)) {
    
                            if (form_is_gravity_forms) {
                                    var form_id = $(form).attr('id').substring(6);
                                    // Gravity Forms won't allow the form to submit if this is already true
                                    window['gf_submitting_'+form_id] = false;
                            }
    
                            e.preventDefault();
                            return false;
    
                    }
    
                    return true;
    
            };
    • This topic was modified 1 year, 3 months ago by Leo.Lin.
    • This topic was modified 1 year, 3 months ago by Leo.Lin.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make check_and_possibly_show_otp_field return Promise when using async/await.’ is closed to new replies.