Conditionally render a page

How to Conditionally render a page based on a user role
Like i have a chnage password page which has a form so i want to show the form only when the user role is admin and or else show 401


Nd i dont want to go by above method becz if i directly try to access that page than it will still be visible

Hi, @Sneha_Borkar

Please take a look at these topics where we have already suggested solutions for similar requests:

Regards, Marina

I have used this visibility logic for the full page block which contains a form
this works as expected
but for non Admin login its shows the form for a few seconds and than disables
Any solutn for it?

@Sneha_Borkar, this is because you have a lot of logic before block visibility is set to false. There are two options to solve this issue:

  1. Set display false by default for the form. This way, when the logic is triggered, the form will be displayed or not.
  2. This option uses dataLoaded and showForm. The second option is better because you can show the spinner for the whole page on the dataLoaded false property, and when the logic loads, show the form you want or not.

Regards, Marina

1 Like

Hi @Marina.Rudenko

So on page enter, i’ll do the API call etc and set 2 values show form if admin and data loaded
and then give visibility logic where it will check for these 2 variables ryt?
and where to get “and” from just next to return in the 1st image

So on page enter, i’ll do the API call etc and set 2 values show form if admin and data loaded
and then give visibility logic where it will check for these 2 variables ryt?

Yes, you are right. Be sure to set display false by default for the form before.

and where to get “and” from just next to return in the 1st image

This block can be found in the Logic section:

Regards, Marina

Thanks alot @Marina.Rudenko
This works as expected!!!