Jake Vanderwerf
9 days ago 47e77f9fac1155c536b2b87fec552c7fcce66fa6
assets/js/concise/Referral.js
@@ -35,7 +35,7 @@
      };
      this.forms = this.container.querySelectorAll('form');
      this.popup = new window.jvbPopup({
      this.popup = window.jvbPopup.registerPopup({
         toggle: this.toggle,
         popup: this.container,
         name: 'Referral Box',
@@ -640,8 +640,9 @@
               referral_code: formData.get('referral_code')
            };
            if (formData.get('cf-turnstile-response')) {
               data['cf-turnstile-response'] = formData.get('cf-turnstile-response');
            const turnstileInput = form.querySelector('input[name="cf-turnstile-response"]');
            if (turnstileInput && turnstileInput.value) {
               data['cf-turnstile-response'] = turnstileInput.value;
            }
            if (!data.name || !data.email || !data.referral_code) {
@@ -652,18 +653,19 @@
         } else if (form.id === 'login-form') {
            let data = {
               type: 'login',
               email: formData.get('login_email'),
               user_email: formData.get('login_email'),
               context: {
                  redirect_to: window.location.href + '?seeReferral=1'
               }
            };
            if (formData.get('cf-turnstile-response')) {
               data['cf-turnstile-response'] = formData.get('cf-turnstile-response');
            const turnstileInput = form.querySelector('input[name="cf-turnstile-response"]');
            if (turnstileInput && turnstileInput.value) {
               data['cf-turnstile-response'] = turnstileInput.value;
            }
            if (!data.email) {
            if (!data['user_email']) {
               result.message = 'Please fill in your email';
            } else {
               result = await this.makeRequest('magic', data);
               result = await this.makeRequest('auth/magic', data);
            }
         }
@@ -682,7 +684,7 @@
   async makeRequest(endpoint, data) {
      const validEndpoints = [
         'magic',
         'auth/magic',
         'auth/register'
      ];
@@ -690,16 +692,11 @@
         return { success: false, message: 'Invalid endpoint' };
      }
      const response = await fetch(`${jvbSettings.api}${endpoint}`, {
      const response = await window.auth.fetch(`${jvbSettings.api}${endpoint}`, {
         method: 'POST',
         headers: {
            'Content-Type': 'application/json',
            'X-WP-Nonce': window.auth.getNonce(),
         },
         body: JSON.stringify(data)
      });
      // Add error handling to see the actual response
      if (!response.ok) {
         const errorText = await response.text();
         console.error('Error response:', response.status, errorText);