Redirect Logged In User from Landing Page - HELP ASAP

I’ve been searching the forum but it doesn’t seem like anyone discussed this issue. I’m trying to automatically redirect a logged in user to the appropriate page when they land on my website. To explain my issue some more, if a user was previously logged in to my site and exited the page without logging out their information is automatically stored and when they appear on the website again they still appear as logged in. However, they are stuck on the landing page because you can only be directed to the inner site on login. This poses an issue. Therefore, I am trying to route that logged in user to the appropriate page whenever they land on my site.

I’ve been playing around with the code in the site part of my page and so far came up with this, but it’s not working. Any assistance would be greatly appreciated as this is preventing me from finishing my site.


import { local } from 'wix-storage';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';

export function myRouter_Router(request) {
    $w.onReady(function () {
 let user = request.user;
 let User = wixUsers.currentUser;
 let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
 let isLoggedIn = user.loggedIn; // true
        console.log("User is logged in")
        wixData.query("Employers")
            .eq("_id", userId)
            .find()
            .then((results) => {
 if (results.length > 0) {
                    wixWindow.lightbox.close('#login')
                    wixLocation.to("/members-all");
                } else {
                    wixData.query("Employees")
                        .eq("_id", userId)
                        .find()
                        .then((results1) => {
 if (results1.length > 0) {
                                wixWindow.lightbox.close('#login')
                                wixLocation.to("/Employee-Dashboard");
                            }
                        })
                }
            })
            .catch((err) => {
                console.log("User is not logged in");
                wixLocation.to("/home");

            })
    })
}