Trying to redirect using rules to my custom domain

Hi when am trying to redirect using rules to my custom domain, and when i trigger the /continue api, I end up landing on the same custom domain instead of returning back to the auth0 rule? Can you help?

Hi @ankitaa,

Thanks for reaching out to the Auth0 Community!

It sounds to me like you are encountering a redirect loop. If so, I recommend resuming the authentication flow in your Rule by checking the context.protocol property.

function (user, context, callback) {
    if (context.protocol === "redirect-callback") {
        // User was redirected to the /continue endpoint
    } else {
        // User is logging in directly
    }
}

Reference: Redirect Users from Within Rules

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thanks,
Rueben

What am I suppose to add in the if and else conditions as described above?

Can you help me out with an example, currently my continue url is https://staging-environment.us.auth0.com/continue?state=${state} and my redirect url is context.redirect = {
url: http://localhost:3000/login?token=${token},
};

if (context.protocol === “redirect-callback”) {
// User was redirected to the /continue endpoint
context.redirect = {
url: https://staging-environment.us.auth0.com/continue,
};

} else {
      context.redirect = {
url: `http://localhost:3000/login?token=${token}`,

};
}

is this something that you are suggesting?

1 Like

Hi @ankitaa,

Yes, that is correct.

How does it work for you?

Thanks,
Rueben

worked fine and solved the issue thanks

1 Like