I have a database i.e., member data, where a custom form data is stored. When a user login, we have to match the email of the current user with the database, if matched, find the role attached to it in the database, if admin redirect to admin page, if employee, redirect to employee page.
I have drafted the code below, but unable to redirect. Help me with this. @Yisrael (Wix)
import { currentMember } from 'wix-members'; import { authentication } from 'wix-members'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady(() => { currentMember.getMember() .then((member) => { const id = member._id; const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`; const emailId = member.loginEmail; $w("#emailId").text = emailId; wixData.query("Onboard") .eq('eMail', emailId) .find() .then((res) => { if (res.items.length > 0) { console.log("ok") const item = res.items[0]; const itemRole = item.role; $w("#role").text = itemRole; if (itemRole.value == "admin") { authentication.onLogin(() => { wixLocation.to("/admin"); }) } else { console.log("nothing to show"); } const itemImage = item.image; $w("#image").src = itemImage; const itemName = item.fullName; $w("#image").tooltip = itemName; } else { console.log("noItemFound"); $w("#role").text = 'notGiven'; } }) return member; }) .catch((error) => { console.error(error); }); }); $w("#logout").onClick(() => { authentication.logout() })