Beta Launch: Viewable pages (Logged in) vs (Non-logged in)

Hi everyone,

I’m currently running a beta test on my platform to check for bugs, and things that needs to be fixed.

I’m having an issue that I would like to get help with.

  1. I have our “frontend” which is viewable to non-logged in users only
  2. I have our “backend” which is viewable to logged in users only

The main issue I need to resolve is this, when “logged in users” decide to close their tab, and maybe re enter our website using our main domain, this does not work because it’s only viewable to non-logged in users.

This is causing a little headach, as users are reporting that they are not able to access our homepage. Any thoughts on solution here?

NOTE: I dont want “logged in” users to be able to access our frontend, as it looks quite weird, having a vertical nav bar and scrolling around on our homepage.

I can’t figure out from your description what’s going on. Can you try again with screen shots?

The main issue I need to resolve is this, when “logged in users” decide to close their tab, and maybe re enter our website using our main domain, this does not work because frontend is only viewable to non-logged in users.

Here is the recording showing this:
https://imgur.com/a/f0Cu8g6

I could alternatively allow all our frontend sites to be viewable to all users, but I dont like the touch and feel of this, as its not very user friendly to view the sites like this:
https://imgur.com/a/f0Cu8g6

Would it work to have some custom code on the home page that basically says “if this user is logged in, take them to their dashboard instead of the home page”?

1 Like

Typically you could put some CTA on the home page for logged in users to navigate into dashboard area sort of…
Or you could also have website on mydomain[.]com and the app/dashboard on app[.]mydomain[.]com

Or as Davit suggested we could give small script that redirects from home to specific page if the user is logged in - however they will not see the page in any case as logged in user

Hi Artur,

Is it possible to put the app on a subdomain without using more of my domain plan? If so, that would be the best solution for me.

I would love to have this as the current solution :sweat_smile: Would you be able to help me create it?

Easy-peasy. I’ll try to find a spare moment in the next day or so to write it.

Put this script in your home page’s page settings in the Code Inside Footer section. If the slug for your dashboard is something other than /dashboard, then change that in the script.

<script>
    function isLoggedIn() {
        return (typeof(logged_in_user) === "object");
    }
    document.addEventListener("DOMContentLoaded", function() {
        if (isLoggedIn()) {
            document.location.replace("/dashboard");
        }
    });
</script>
1 Like

I tried the script and it worked partially. As I have two dashboard slugs /dashboard-user, as well as /dashboard-manager. They get to any of these dependent on their user access such as “manager” or not. I tried to amend it below; but did not get it to work either:

<script>
    function isLoggedIn() {
        return (typeof(logged_in_user) === "object");
    }
    document.addEventListener("DOMContentLoaded", function() {
        if (isLoggedIn()) {
            if (document.location.pathname === "/dashboard-manager" || document.location.pathname === "/dashboard-user") {
                document.location.replace(document.location.pathname);
            } else {
                document.location.replace("/dashboard-manager");
            }
        }
    });
</script>

I don’t understand what your change was supposed to accomplish. Can you say it in words?

If the logged in user is not a manager, they should be directed to “/dashboard-user” when accessing the homepage.

However, if the user is a manager, they should be directed to “/dashboard-manager” when accessing the homepage.

I hope that was clearer and thanks for taking the time!

OK, that makes sense. But I don’t think looking at the slug is the right way to ask whether the logged in user is a manager. What makes a user a manager – is it membership in a group?

The user group set up in Softr settings is the determinator. If they are a manager, they have a custom domain, all other users “Logged in Users” go to “/dashboard-user”.

OK that makes sense. I know the group information is available to custom code, but I don’t have any code for that right now so will have to poke around in the debugger. If anyone else knows how to write that code off the top of their head, please jump in!

1 Like

@erikm3103 is manager or not identified based on email domain ?

It is based on email domain yes.

Right, but we would not want to copy that logic into the custom code as that would violate “don’t repeat yourself” and set up a future bug where someone changes the logic in the group definition and breaks the custom code in a way that would be hard to diagnose.

Not ideal but could work ?

<script>
    function isLoggedIn() {
        return (typeof(logged_in_user) === "object");
    }

    function isManager() {
        return isLoggedIn() && logged_in_user.softr_user_email.endsWith('emaildomain');
    }
    document.addEventListener("DOMContentLoaded", function() {
        if (isLoggedIn()) {
            if (isManager()) {
                document.location.replace("/dashboard-manager");
            } else {
                document.location.replace("/dashboard-user");
            }
        }
    });
</script>

change emaildomain to proper value

1 Like

That did the trick - in my case it will be sufficient solution. Thanks to both of you!