Open wet6123 opened 2 weeks ago
The changes introduced in this pull request enhance the user login flow by implementing location-based redirection. In the Index
component, the useLocation
hook is utilized to capture the user's intended pathname, which is stored in session storage upon login. The CallbackIndex
component is updated to retrieve this redirect path from session storage after authentication, ensuring users are directed to their intended page instead of the root path.
File | Change Summary |
---|---|
frontend/src/pages/Index.tsx |
Added useLocation import and a constant location to capture the pathname for redirection. Updated handleLogin to store the redirect path in session storage. |
frontend/src/pages/auth/callback/Index.tsx |
Modified CallbackIndex to retrieve the redirect path from session storage and navigate to it after setting tokens. |
Objective | Addressed | Explanation |
---|---|---|
Redirect users to their intended page after login failure (#308) | ✅ |
CallbackIndex
component for handling redirection after authentication are directly related to the modifications in the Index
component, which also focuses on managing user login and redirect paths.enhancement 🌟
In the burrow where we hop and play,
A path was lost, but now it's okay.
With every login, we find our way,
To the page we seek, come what may!
Hooray for redirects, let’s cheer and sway! 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
@devleejb Oh, I forgot to mention about the strict mode. I stored the previous URL at the session storage. And then when login success, use the URL and remove it. In strict mode, this code will run twice and the URL will be gone. Then it goes to "/". So, if you disable strict mode, it works fine. Or I can change it not to remove the URL at the session storage. To ensure that it works well even in strict mode.
@wet6123 I believe it should also work well in strict mode. What do you think?
@devleejb I think it's better to make it work in strict mode. I can finish it until this weekend.
What this PR does / why we need it:
Store previous page URL before login. Redirect user back to stored URL after successful login. Add default redirect to home page if URL doesn't exists. Until now, Codepair always redirects you to home after login failure. This allows you to redirect to the intended location.
Which issue(s) this PR fixes:
Fixes #308
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes