umami icon indicating copy to clipboard operation
umami copied to clipboard

Loop when login page not accessed directly

Open Maxime-J opened this issue 2 months ago • 3 comments

Describe the Bug

Congrats for launching v3!

There seems to be a login issue.

When an unauthenticated user doesn't go directly to the login page (/login), accessing for example / or /dashboard, the login page would loop. Note that the user is properly logged in even if he stays on login page, meaning that he can manually go to /websites.

Cause: v3 is now using router.push for login page redirection when authentication is needed.

https://github.com/umami-software/umami/blob/6ba9c1c40c398020a9720a7d2ad4ecfa1c4639bc/src/app/(main)/App.tsx#L10-L25

But query from useLoginQuery won't be updated

https://github.com/umami-software/umami/blob/6ba9c1c40c398020a9720a7d2ad4ecfa1c4639bc/src/components/hooks/queries/useLoginQuery.ts#L6-L22

And App would still go to router.push('/login'), hence the loop.

Maybe there was a specific reason you changed for router push, but reverting to the old way using window.location.href would fix this. Otherwise, tanstack offers a way to invalidate a specific query: queryClient.invalidateQueries({ queryKey: ['login'] })

Database

PostgreSQL

Relevant log output


Which Umami version are you using? (if relevant)

No response

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Maxime-J avatar Nov 08 '25 17:11 Maxime-J

Confirmed. will get out a fix

franciscao633 avatar Nov 08 '25 17:11 franciscao633

@Maxime-J

I have looked over your issue, apparently I was having the same issue and more likely only on the local machine due to the hard-coded redirects. Since Next.js navigation (router.push) does not trigger a full page reload and instead relies on React’s client-side routing, it preserves component state which can interfere with the expected behavior.

router.push is not properly recommended to handle auth related stuffs but for basic navigation. I hope my proposed fix helps you out.

metaloozee avatar Nov 08 '25 19:11 metaloozee

Saw your merged PR @metaloozee, going the location.href way requires to handle BASE_PATH env manually, like it was in 2.19

window.location.href = `${process.env.basePath || ''}/login`;

They'll most likely catch it up though.

Maxime-J avatar Nov 09 '25 12:11 Maxime-J

relevant https://github.com/umami-software/website/issues/234

Note: Direct visiting the /analytics route currently returns 404, and /analytics/eu causes a too many redirects error — two additional bugs that need attention.

2u841r avatar Nov 11 '25 15:11 2u841r