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!