Skip to content

Infinite Redirect Loop When Home URL is current URL #2581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
jeremysawesome opened this issue Jan 12, 2024 · 6 comments
Closed
4 tasks done

Infinite Redirect Loop When Home URL is current URL #2581

jeremysawesome opened this issue Jan 12, 2024 · 6 comments
Assignees

Comments

@jeremysawesome
Copy link

jeremysawesome commented Jan 12, 2024

Preliminary Checks

Reproduction / Replay Link

https://gitlab.com/jeremysawesome/clerk-minimal-reproduction

Publishable key

pk_test_dG9nZXRoZXItZWdyZXQtMzUuY2xlcmsuYWNjb3VudHMuZGV2JA

Description

If the Home URL and the current url are the same, and there is a SignIn or SignUp component mounted on the page, then Clerk will infinitely redirect.

Here's a gif to illustrate

brave_Rvw0su1pU5

Steps to reproduce:

  1. Drop the index.html file into a directory where it can be accessed via browser
    (i.e. $DEVHOST/clerk-minimal-reproduction/).
  2. Adjust the script src and publishable key for your Clerk app.
  3. Navigate to Developers > Paths in your Clerk Dashboard
  4. Change your Application homepage to /clerk-minimal-reproduction/
  5. Do the same for all the User redirects in Configure > Account Portal > Redirects
  6. Log in or sign up for your application via $DEVHOST/clerk-minimal-reproduction/ in your browser.

Behold the redirect loop.

Expected behavior:

  1. Don't redirect to the same url (in the case where the Home URL and current URL are the same)
  2. Output a warning or error in the console if the preconditions fail.
  3. Don't render the components if the preconditions fail (i.e. the urls are the same).

Actual behavior:

Clerk initiates an infinite redirect loop. It's hard to find the reason why unless you are able to pause the page after the Clerk message appears in the console but before the page reloads.

Environment

Not necessary. This is a simple index.html page hosted at a publicly accessible url.
@jeremysawesome jeremysawesome added the needs-triage A ticket that needs to be triaged by a team member label Jan 12, 2024
@younessaita
Copy link

I'm facing the same issue currently, any fix?

@Eventrope
Copy link

Same issue!

@linear linear bot added prioritized This issue has been triaged and the team is working on it confirmed and removed needs-triage A ticket that needs to be triaged by a team member prioritized This issue has been triaged and the team is working on it labels Jan 29, 2024
@panteliselef panteliselef self-assigned this Jan 30, 2024
@panteliselef
Copy link
Member

Hello @jeremysawesome

By default the <SignIn /> will perform a route navigation to / if user is signed in. This is because the common pattern is to mount the component a different page (e.g /sign-in) than your home page.

To fix this in vanilla JS you can simply check if the user exists and avoid mounting the component.

<script>
    async function clerkLoad() {
        await Clerk.load()
        if(Clerk.user) return ; // This line is needed
        const signInContainer = document.getElementById("SignIn")
        Clerk.mountSignIn(signInContainer)
    }
</script>

@panteliselef
Copy link
Member

I'm closing due to inactivity, if the snippet above does not solve the issue, feel free to reopen

@jeremysawesome
Copy link
Author

Hi @panteliselef
Thanks for the response. I appreciate the code suggestion and will likely implement it.

I still think that, rather than redirecting, the component should just not be rendered.

As it is the warnings that are output in the console cannot be read unless one can expertly stop the redirect loop.

That said, I think that #2251, when it is released, will resolve some of the confusion.

@clerk-cookie
Copy link
Collaborator

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@clerk clerk locked as resolved and limited conversation to collaborators Feb 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants