Permissions with Published/Preview Problem

I am hoping someone can help shed some light on an issue I have been trying to resolve for several hours now. I have a landing page where any user can subscribe and join a waitlist. After they subscribe, I send an email using SendGrid’s v3 API, then display their waitlist position and a thank-you message. The code works OK in preview (performs all functions described above), but does not work on the live site.

All fetch requests are made in the backend. On the live site, the code fails with an “Uncaught (in promise)” error when I attempt to import the backend subscribeUser function, seen via my browser’s dev-tools. This does not happen in the preview site. I have tried setting all permissions to be as lenient as possible, but still receive an error.

I have included relevant snippets of my code below, and would appreciate any help in solving this problem. I am also happy to share the site URL directly with a Wix Code Admin.
#backend #fetch #permissions #livesite


Home page:

import {subscribeUser} from 'public/simpleSubscribe.js'
export function signupbutton1_click(event) {
    subscribeUser(<page elements>);
}

Public JS file (simpleSubscribe.js), permission set to “Anyone”:

import {backendSubscribe} from 'backend/subscribeUtil'  <----- Error here in browser devtools 
export async function subscribeUser(<page elements>) {
 let subscriptionStatus = await backendSubscribe(userEmail)
 if (subscriptionStatus == "error"){
        // <handle page elements>
    } else {
        // <handle page elements>
    }
}

Backend JSW file (subscribeUtil.jsw), permission set to “Anyone” (intend to change to admin-only if possible):

import {sendSignupEmail} from 'backend/email';
import wixData from 'wix-data';

export async function backendSubscribe (userEmail){   
    // <handle if user subscribed or other errors, otherwise...>   
    let wlNum = await sendSignupData(userEmail, refID); 
}

async function sendSignupData(einput, refID) {
    // <do database query to get necessary waitlist number>
    sendSignupEmail(einput, refID, waitlistNumber).then(response => console.log(response));
    return waitlistNumber;
}

Thanks!

Bumping this – would really appreciate some insight/guidance.

Hello, you know how I can see the code of my website?

I have the same issue, I catch the rejection and the error says “Error: Not Found”, still not sure what could cause code to not work in Live mode (but it does on Preview)

Solved

1- you can only call web modules (ends in *.jsw), see Velo Web Modules: Calling Backend Code from the Frontend | Help Center | Wix.com

2- do not nest backend files inside folders, that was my issue. I have my import like this

import  { getRoutesByService }  from  'backend/commands/getRoutesByService'; 

but after moving the file out of the commands/ folder it changed to

import  { getRoutesByService }  from  'backend/getRoutesByService'; 

hope this helps!