If Logged In - Login Page Redirect to Other Page

Hey TB Community-

I wanted to add some script to auto redirect if someone goes to the login page and they are already logged in. Right now its shows text that says the user is already logged in. However, on some of my apps, the login page doesn’t have links to click to go to another page.

Therefore, I wanted something to redirect to another page that will detect role and send over the correct page. I’m sure someone could code in the actual detection of loggedin user role and include that in the redirect, but I already have the redirect page built for other functionality and decided it would be easiest to leverage that.

Javascript on Login Page Javascript Tab:
NOTE: Change “/redirect-role” with your page slug

setTimeout(function () {
    // Redirect to the redirect-role page
    window.location.href = "/redirect-role";
}, 250); //Adjust number to increase or decrease wait time before redirect

Redirect-role page Javascript:

var role = "{loggedInUser.Role}";

$(document).ready(function(){
    if (role === "Acct Admin") {
        window.location.href = "/home-aa";
    }
     else if (role === "User") {
        window.location.href = "/home-u";
    }
    else if (role === "Reviewer") {
        window.location.href = "/home-r";
    }
    else if (role === "Super Admin") {
        window.location.href = "/home-sa";
    }
});

Redirect-role page security

My app does not apply a layout to the redirect-role page.

If anyone could test this on their app to see if it works, I would be appreciative.

Adam

I got this to work using just the page rules tab on the login page. I do not use login redirects either.