Full Page Reload After Forgot Password When Using redirectTo Package: @daveyplate/better-auth-ui Ver
When using redirectTo={domain} with React Router and the built-in forgot-password flow, a full page reload is triggered after submitting the form and the email is sent.
This causes an unwanted reload (flicker) and breaks client-side navigation.
Expected Behavior
After a successful forgot-password request:
I should stay on the /auth/forgot-password page, or
Be redirected to /auth/sign-in via React Router navigation without a full page reload.
Steps to Reproduce
Wrap app in using:
<AuthUIProvider
authClient={authClient}
redirectTo={window.location.origin}
replace={(path) => navigate(path, { replace: true })}
Link={({ href, ...props }) => <NavLink to={href} {...props} />}
{children}
Navigate to /auth/forgot-password
Submit valid email
Observe: full page reload to /auth/sign-in
Investigation
The reload is triggered because redirectTo builds a full URL (http://localhost:3000/auth/sign-in), which then gets passed back into window.location.href = ..., causing a hard reload.
Even when replace is implemented, it's bypassed in favor of redirectTo.
Proposed Fix
One of the following would help:
Provide a lifecycle hook (like onForgotPasswordSuccess) to override the redirect.
Allow redirectTo to be respected only for actual link-building, not for internal redirects after submission.
Make replace() intercept even full redirectTo URLs like http://localhost:3000/auth/sign-in.
4 Replies
window.location.origin
What does that mean? is this like a expected behavior in the package?
I would guess that it need to be /auth/forgot-password
yeah after the auth/forget-password
it sends the forget password to email and redirects to the auth/sign-in
the expected behaviour is either stay in the forget-password route or navigate to /sign-in page without page reload. it affects the user experience
@daveycodez
I addressed this in the GH issue
need to configure navigate not just replace
and get rid of redirectTo={window.location.origin}
@daveycodez can you check dm if redirect is replaced by navigate then it solves the page reload but the providers signin doesn't work
I think there is issue on redirectTO