Hi…
I was try to create a button to check whether the current user id is available in a database or not,
If it available it will redirect the user to certain page,
If it unavailable it will redirect the user to other page.
Here is the code that I write:
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
export function update_click(event, $w) {
let user = wixUsers.currentUser;
let userId = user.id;
// check if there is an item for the user in the collection
return wixData.query(“penyedia_jasa”)
.eq(“_id”, userId)
.find();
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
wixLocation.to (“http://wix.com”); ;
}
else {
wixLocation.to (“http://google.com”); ;
}
};
I really looking for your help.
Thank you very much before.