how to hide whitelist user field only to owner or admin?

NodeBB Plugins
  • I was able to add user field on user creation by using hook filter:user.create. Now I noticed that the field is not generally available on the profile and to make it available we need to use the filter:user.whitelistFields . Please correct me if I am wrong.

    Now if I add my field to the whitelist I noticed that the field gets exposed to everybody. How can I make this field only available to the owner or admin?

    Thanks!

  • If you only want to make it available on the profile page you can use the filter:account/profile.build hook and load the value from db and set it the user is self or admin.

    All the required data should be passed to the build hook.

    	userData.isAdmin = isAdmin;
    	userData.isGlobalModerator = isGlobalModerator;
    	userData.isModerator = isModerator;
    	userData.isAdminOrGlobalModerator = isAdmin || isGlobalModerator;
    	userData.isAdminOrGlobalModeratorOrModerator = isAdmin || isGlobalModerator || isModerator;
    	userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator;
    	userData.isSelf = isSelf;
    
  • @baris said in how to hide whitelist user field only to owner or admin?:

    ad the value from db and set it the user is self or admin.

    perfect. Thanks!


Suggested Topics