Sure - most of the code is the same as the original post, except for the part that I replaced with yours. The suppressAuth is in the backend (in the .find() function). Thank you!
Front-End Code:
import { authentication, currentMember } from 'wix-members';
import {local, session, memory} from 'wix-storage';
import { myUserType } from 'backend/userType.jsw';
let email;
$w.onReady(function () {
//get current user email
console.log("frontend");
currentMember.getMember()
.then((member) => {
console.log("user is logged in")
email = member.loginEmail;
session.setItem("email", email);
console.log("got current member, email: ", email);
})
myUserType(email).then( product => {
console.log(product);
if (product == "chef") {
console.log("user type: chef");
$w("#button3").link = "/explore";
} else {
console.log("user type: user");
$w("#button3").link = "/contact";
}
})
});
Back-End Code:
import { contacts } from 'wix-crm-backend';
export async function myUserType( email ) {
return contacts.queryContacts()
.hasSome('primaryInfo.email', email)
.find({'suppressAuth': true})
.then( (results) =>{
if (results.length > 0) {
console.log(results);
let userType = results.items[0].info.extendedFields["custom.user"];
console.log(userType);
return userType;
} else {
console.log("[myUserType]::No record was found when querying queryContacts. Email was: "+email);
return ""; // no record was returned so return blank usertype
}
})
.catch( (error) => {
console.log("[myUserType]::Error occurred trying to run queryContacts. Error was: "+ error.message);
return ""; // no record was returned so return blank usertype
});
}