Code running perfectly on preview, not running live

Hi guys ! I created a long and boring code that is perfectly running on preview mode, however I tried live and nothing happen, I don’t understand why. If someone have any idea, I would be glad to offer ice cream <3
More seriously, I am supposed to show the website to my client tuesday, so any help would be really appreciated!

The expected behavior :
When user clicks on button2:
1 - Password, email and phone are stored in the PrivateMemberData → the user is registered
2 - Based on the email of the user, I run a query in order to extract his contactID
3 - I store the contactID with other information related to the user in a new database (Profil patient)
4 - I log the user in
5 - I redirect the user to a welcome lightbox

You can run the code using the following link : https://valentinloppe.wixsite.com/oncopole
You go to “connexion”, then you click on “je n’ai pas encore de compte”

The code :

import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import { session } from 'wix-storage';

$w.onReady(function () {

    $w('#button2').onClick(() => {
 if ($w("#firstName").value === "") {
            $w("#text13").text = "Merci de renseigner votre prénom"
            $w("#text13").expand()
        } else if ($w("#lastName").value === "") {
            $w("#text13").text = "Merci de renseigner votre nom de famille"
            $w("#text13").expand()
        } else if ($w("#cps").value === "") {
            $w("#text13").text = "Merci de renseigner votre numéro de CPS"
            $w("#text13").expand()
        } else if ($w("#datePicker1").value === "") {
            $w("#text13").text = "Merci de renseigner votre date de naissance"
            $w("#text13").expand()
        } else if ($w("#email").value === "") {
            $w("#text13").text = "Merci de renseigner votre adresse email"
            $w("#text13").expand()
        } else if ($w("#password").value === "") {
            $w("#text13").text = "Merci de renseigner votre mot de passe"
            $w("#text13").expand()
        } else if ($w('#checkbox1').checked) {
 let emails = [];
 let labels = [];
            finale()

        } else {
            $w('#text13').expand();
        }
    });
});

export function text14_click(event) {
    wixWindow.lightbox.close()
    wixWindow.openLightbox("Connection")
}

function connection() {

 let email = $w('#email').value
 let password = $w("#password").value

    wixUsers.login(email, password)

        .then(() => {
            console.log("User is logged in");
            session.setItem("prenom", $w('#lastName').value);
            wixWindow.openLightbox("Bienvenue")
        })
}

function register() {

 let emails = [];

    emails.push($w('#email').value);

    wixUsers.register($w('#email').value, $w('#password').value, {
 "contactInfo": {
 "firstName": $w('#firstName').value,
 "lastName": $w('#lastName').value,
            }
        })
        .then((result) => {
 let resultStatus = result.status;
            console.log(result)
            console.log(resultStatus)
        })
        .catch((err) => {
            savings();
        })
}

function savings() {

    wixData.query("Members/PrivateMembersData")
        .eq("loginEmail", $w('#email').value)
        .find()
        .then((results) => {
 let Result = results.items[0]
 let ResultID = Result._id;
            console.log(ResultID)

            $w("#dataset1").setFieldValues({
 "nom": $w('#firstName').value,
 "prenom": $w('#lastName').value,
 "cps": $w('#cps').value,
 "telephone": $w('#phoneNumber').value,
 "email": $w('#email').value,
 "dateDeNaissance": $w('#datePicker1').value,
 "patientId": ResultID
            })
            $w("#dataset1").save()
            session.setItem("ResultID", ResultID);
            console.log("les données sont stockées")
            connection()

        }).catch((err) => {
            console.log(err);
        })

}

async function finale() {
 await register()
    console.log("l'utilisateur est enregistré")
}

Make sure that you have the correct collection permissions and that you have synced the sandbox collection to Live .

Ice cream sounds good…

Hi ! Thank you for your answer :slight_smile:
I actually have set up all the permissions to anyone and my collections are synced :cry:
Ice cream is melting… lol!

What doesn’t work? You say “nothing happens”, but do you mean absolutely nothing ? Or do you mean that “some stuff” happens, but not enough, or not what you want?

A few things (so far)…

What page has the code that you posted? I can’t find it.

Note: The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality. So what does that mean? It means that running in Preview might look like it works, but it’s only working since you are the user that is logged in while in Preview.

In the loginButton1_click() function in the master-page.js, t he call to wixUsers.logout() does not return a Promise, therefore the code in the .then() never runs:

        wixUsers.logout()
            .then(() => {
                // this never runs
                $w("#loginButton1").label = "Connexion";
                $w("#profileButton").hide();
                wixLocation.to('/home')
            });

Just get rid of the .then().

In the Connection lightbox code, the second line of code in the function below won’t ever run, since you first close the lightbox.

export function text15_click(event) {
  wixWindow.lightbox.close()
  wixWindow.openLightbox("Inscription")
}

Well, that’s what I see so far. Since I don’t know exactly what isn’t working it’s hard to know what’s wrong.

I would suggest liberal use of console.log() statements so that you can see what’s happening in the browser’s developers console while you are running the Live site.