web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / If Authenticated go to...
Power Pages
Unanswered

If Authenticated go to home page, else go to Login page - how can I write this JS code - and where to use?

(0) ShareShare
ReportReport
Posted on by 520
Categories:
I have the same question (0)
  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at
    Re: If Authenticated go to home page, else go to Login page - how can I write this JS code - and where to use?

    Hi @Robert94 

     

    You can mix liquid and JS together to achieve this. High-level idea 

     

    $(document).ready(function () {
     var roles = "{{ user.roles }}";
     console.log(roles);
     if(roles.contains("Administrators") > 0)
     alert("I am Admin");
    });
    

     

    The above script is using web role. Instead of alert, you can redirect to the specific page. 

     

    official example 

     

    {% if user %}
     
    Hello, {{ user.fullname | escape }}!
     
    {% else %}
     
    Hello, anonymous user!
     
    {% endif %}

     

    Official URL: Please click here 

     


    Hope it helps. 
    ------------

    If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 66

#2
Fubar Profile Picture

Fubar 45 Super User 2025 Season 2

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 31 Super User 2025 Season 2

Last 30 days Overall leaderboard