How to hide an element on page based on current user profile

Hello,

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.

Can you please help me with this code?

Thank you very much.
Regards,
Sanjay

Ok, how to solve your problem?

  1. You have DATABASE-A
  2. You have DATABASE-B
  3. You will have to search for an User-Email in both DBs after a User-Login.

How would it work and what would be the flow?

  1. User logs in no matter if it is a TALENT or an EMPLOYER.
  2. User can be identified by → E-MAIL and USER-ID.
  3. When you got the identification-values you start to search/filter both of your DBs.
  4. Then you get the result of both DBs and know exactly to which of both DBs he belongs to.

Ok, lets go more detailed…

  1. Get loged-in-user-info…
    https://www.wix.com/velo/reference/wix-users/currentuser
  2. Query + Filter your DBs…
    https://www.wix.com/velo/reference/wix-data/query
    https://www.wix.com/velo/reference/wix-data/wixdatafilter
  3. At least you do a if-else-query to identify the right button to show or to hide.

Thats it! Now try to put all together and generate your needed code.

Good luck and happy coding.:wink:

hi, thanks very much for your quick reply and suggestion. I will try it out and confirm if its working. Regards,

Hi, I wrote the following Code but it does not seem to be working. Can you please check if I wrote it correctly. thanks

@pandit1

  1. 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…

  2. 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.

And of course you can do code-improvements, too.

Hi Sanjay,

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.

Thank you.

Will be soon available here…


You want to tell me more about your wished functions?
I can integrate it into the shown Login-System.

Interested in cooperate work? → Send me a mail. (to be found in my profile).

Your benefit? → Free working solution with your wished functionality :wink: (when the environment-system is coded completely and is ready to use).

https://www.media-junkie.com/vnloginmgm

hi i need to do the same thing. did you figure it out?

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 —>

  1. Get User By Role - #12 by russian-dima
  2. Login redirect - #10 by pekrzyz
  3. [SOLVED] I'm the owner/admin of the website but why is my role member?
  4. Moderation Panel/Dashboard - #17 by russian-dima
  5. Allow members to create private lists from existing database? - #3 by russian-dima
  6. Is there a way to change the autofill input color - #8 by russian-dima
  7. Login redirect
  8. 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.

1 Like