Issue with Custom Login Redirection - SDK

Hi everyone,

I’m using the following code on a custom login page to redirect users based on their assigned member roles. However, after logging in, the user is first redirected to the homepage before being redirected again (after 3-4 seconds) to the correct dashboard page.

I’d like to prevent the initial redirection to the homepage and ensure the user is taken directly to their respective dashboard based on their role. How can I achieve this?

Here’s the code I’m currently using

import { authentication, currentMember } from "@wix/site-members";
import { location } from "@wix/site-location";

$w("#accountloginButton").onClick(async () => {
        const email = $w("#loginEmailInput").value;
        const password = $w("#loginPasswordInput").value;
        await new Promise((resolve) => setTimeout(resolve, 2000)); // 1-second delay
        
        authentication
            .login(email, password)
            .then(async () => {
                console.log("Member is logged in");
                const roles = await currentMember.getRoles();
                const roleIds = roles.map(role => role._id);

                if (roleIds.includes("1a145b9f-6448-46f9-a144-147c0919efd9")) {
                    location.to("/dashboard/soloist-controlpanel");
                } else if (roleIds.includes("9781be63-7e5f-4324-aa79-ebeb1924ae82")) {
                    location.to("/dashboard/enterprise-controlpanel");
                }
            })
            .catch((error) => {
                console.error(error);
                $w("#passwordErrorText").text =
                    error.details?.applicationError?.code === "-19976" ? getErrorMessage("invalidCredentials") : getErrorMessage("loginFailed");
                $w("#passwordErrorText").show();
            });
    });