Check the currentuser is available in a database or not

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.

Hi,
What do get from this code ?
Roi

When I tried to click the button,
nothing happened.
In the backend it said that the error part is here:

.then( (results) => {

Can you please share a link to your site so we can inspect ?
Roi

No problem
https://bangunrumahind.wixsite.com/bangun-rumah

https://bangunrumahind.wixsite.com/bangun-rumah/penyedia-jasa-index

Hi,
You had some syntax errors (some missing “} )” )

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(`/pencari-jasa/${wixUsers.currentUser.id}`);
			} else {
				wixLocation.to(`/penyedia-jasa/${wixUsers.currentUser.id}`);
			}
		});
}

Good luck!
Roi

thank you very much Roi.
That’s what I need.