Fix login redirection to requested page after authentication#1912
Open
Nowaker wants to merge 1 commit intohackmdio:developfrom
Open
Fix login redirection to requested page after authentication#1912Nowaker wants to merge 1 commit intohackmdio:developfrom
Nowaker wants to merge 1 commit intohackmdio:developfrom
Conversation
Member
|
Hi @Nowaker, Thank you for your PR! P.S. Glad to see you here, howdy! |
Signed-off-by: Nowaker <spam@nowaker.net>
352d691 to
d47cd95
Compare
Contributor
Author
|
@jackycute Howdy howdy! :) |
jackycute
approved these changes
May 15, 2025
Yukaii
approved these changes
May 15, 2025
Yukaii
requested changes
May 15, 2025
Member
Yukaii
left a comment
There was a problem hiding this comment.
@Nowaker Could you also update other authentication provider, like
codimd/lib/auth/facebook/index.js
Line 26 in b4ec353
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a user attempts to access a protected resource without being logged in, they are correctly redirected to the login page with a
nextparameter preserving their intended destination (e.g.,/?next=%2Fwb0e9nB5T3qecF27Y4xlsg). However, after successful authentication, the application always redirects to the dashboard/homepage instead of returning the user to their originally requested URL.This creates a poor user experience as users must manually navigate back to the content they were originally trying to access.
Solution
The root cause was identified in the email authentication implementation where the
successReturnToOrRedirectparameter was hardcoded to always redirect to the server's homepage.This change properly utilizes the
req.session.returnTovalue that's already being correctly set by thesetReturnToFromRefererfunction:Testing
Manually tested the authentication flow by:
This fix respects the standard behavior of Passport.js's
successReturnToOrRedirectparameter, which will redirect to the URL stored inreq.session.returnToif available, or fall back to the configured redirect URL otherwise.