I am looking for someone to help me with a code that will show or hide an element (button) based on the current user profile that is linked to a data collection.
I have two data collections - “Employers” and “Talent”, and I have 3 site pages - Employer Page, Talent Page, and I also have a landing page that has 2 buttons for navigation. One button for navigation to Employers Page and the second button for navigation to Talent Page.
The Employer page has a login button and the Talent page also has a login button.
I have created login code in a way that details of user logging through Employer page would be created in Employers Collection and details of user logging through Talent page would be created in Talent Collection.
I now want to develop a code on the landing page, which will show or hide the navigation buttons (Employers button and Talent Button) depending on whether the current logged in user belongs to Employers database or Talent database.
You do not have to show your code in a word-document, because you have an implemented forum-option here called —> “Add a code-snipet”, like this one…
an improved code-example…
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(async() => {
let UserDetails = await getUserDetails();
getEmployers(UserDetails);
// getTalents(UserDetails);
});
//Here you get all user-details...
function getUserDetails() {
let user = wixUsers.currentUser; console.log(user)
let userId = user.id; console.log(userId)
let isLoggedIn = user.loggedIn; console.log(isLoggedIn)
user.getEmail()
.then((email) => {
let userEmail = email; console.log(userEmail)
return ({"userID":userId, "userState":isLoggedIn, "userEmail":userEmail})
});
}
function getEmployers(UserDetails) {
let DB = "Employers"
let FIELD = "email"
let VALUE = UserDetails.userEmail
wixData.query(DB)
.eq(FIELD, VALUE)
.find()
.then((results)=> {
let items = results.items; console.log(items)
if(items.length > 0) {$w("#Place ID of Employer-Button here").show();}
else {$w("#Place ID of Employer-Button here").hide();}
});
.catch( (Error) => {let errorMsg = Error; console.error(errorMsg);})
}
I am sure you will be able to complete this code. It is still not complete. Check all console logs to understand whats happening.
I also have a need to create two separate members area for two type of users. Can you please help me how have you worked out separate member areas. I’m using member area provided by wix, but it is not changing as per user. It is same for all type of users.
Are you familiar with Velo-Coding?
If not, i assume you won’t be able to generate such complexe login-system with all it’s coded functions and features on your own.
But i do not want to disillusion you, so you can maybe start here and read all that stuff…
Test it first, this is an old SELF-MADE LOGIN-SYSTEM, where i was able to integrate the functionality you are searching for. It should become a LOGIN-SYSTEM for all different needs and situations (TEST-VERSION / LEARN-VERSION).
Follow the instructions, normaly the old site should still work, i never shut down this site.
Let me know, if this is what you are searching for.
If you wantt start to learn how to generate all that stuff —>
Get User By Role
…and some more…
…you will find a lot of posts, related to that topic (to that shown login-system)
Type in into the SEARCHBAR —> login+system or ----> login+russian and see which posts you can find about this mentioned login-system and how it was build.