Thursday 23 July 2020

PowerApps Portals - Change Default Landing Page For Portal Users




Hi All,

Welcome to my Power Guide Mentorship Program.

Today, I am going to share a #PowerGuideTip16 for PowerApps Portal Developers, who want to manage the redirection of the Portal default landing page.

Requirement:

Redirect Anonymous Portal User to Login Page and Authenticated Portal Users to Home Page,

Solution:

Option 1 - 
Anonymous User Default Landing Page - Login Page
Authenticated User Default Landing Page - OOB Home Page

Go to Portals > Web Template > Home

Update the code as per the following:

{% if user %}
//if a user is logged in then
// Paste OOB Home web template Liquid Code inside this block
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href='~/SignIn';
</script>

{% endif %}





Option 2 - 
Anonymous User Default Landing Page - Login Page
Authenticated User Default Landing Page - Custom Page or other than OOB Home Page

{% if user %}
//if a user is logged
<script>
window.location.href='~/<WebpagePartialURL>';
</script>
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href='~/SignIn';
</script>

{% endif %}


Option 3 - 
Sometimes, you might have the requirement to redirect portal users to the same page after login, where he/she left off, even after closing the browser.

To implement this requirement, you need to use the HTML Local Storage feature.

Set Local Storage -

You need to save the webpage name in Local Storage (browser cache) on each webpage load.

For Example - Let say I have a webpage called submit-request (partial url of webpage), which is associated with case entity form. In order to save the webpage name in local storage. I would use following syntax under Custom JavaScript section:

// Store
var getWebpagePartialURL = location.pathname;
localStorage.setItem("webpagename"getWebpagePartialURL); 


Get Local Storage - 

Now, Go to Home Web Template. You need to write the code to get the local storage value in order to know the webpage name that user had accessed last before closing the browser. And redirect the user accordingly.

{% if user %}
//if a user is logged
<script>
// Retrieve local storage value
var lastAccessedPage = localStorage.getItem("webpagename");
if (lastAccessedPage != null && lastAccessedPage != '')
{
window.location.href = '~/'lastAccessedPage ;
}
</script>
{% else %}

<script>
//if user is not loggedin, redirect user to Login page
window.location.href='~/SignIn';
</script>

{% endif %}

No comments:

Post a Comment

Blogger Widgets