Two export functions

Hi Guys,

I am using the below code for an login page. On the bottom I have two export functions. However when I click #button14 it directs me to the export function (location) of #button15?
Does anybody know if there is something wrong with the code?

Thank you in advance.

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button12”).label = “Logout”;
$w(“#button14”).show();
$w(“#button15”).show();
}
else {
$w(“#button12”).label = “Login”;
$w(“#button14”).hide();
$w(“#button15”).hide();
}
} );

export function button12_click() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button12”).label = “Login”;
$w(“#button14”).hide();
$w(“#button15”).hide();
} );
}

// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
wixLocation.to(‘https://www.et’);
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Free1”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Free1”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button12”).label = “Logout”;
$w(“#button14”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
// Query The “Free1 Database” if form is filled
let userId;
wixData.query(“Free1”)
.eq(“_id”, userId)
.isEmpty(“link-Free1-propertytitle”,userId)
.find()
.then( (results) => {
if (results.items.length > 0) {
$w(‘#button15’).show();
} else {
$w(‘#button15’).hide();
}
} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
// update buttons accordingly
$w(“#button12”).label = “Logout”;
$w(“#button15”).show();
} );

export function button14_click() {
wixLocation.to(/Free1/${wixUsers.currentUser.id});
}

export function button15_click() {
wixLocation.to(/Free1/Propertytitle/${wixUsers.currentUser.id});
}

Maybe you have your buttons connected to the wrong click event handlers? Do you have #button14 connected to button14_click() ?

Hi Yisrael, thank you for your answer. Unfortunately this is not the case, I connected both click event handlers right.

Do you maybe have an other solution:) @yisrael-wix ?

Hey Vincent, I was looking at your problem as you posted…

I suspect that the dynamic page URLs aren’t sufficiently unique and it confuses the dynamic page router. See Editing Your URLs to Make Them Unique . I think if you modify your button14 URL it will solve the problem. Something like:

button14: /Free1/User/${ wixUsers.currentUser.id }
button15: /Free1/Propertytitle/${ wixUsers.currentUser.id }