-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
about the router #26005
Comments
What's your suggestion? |
Hello @lunny, @wxiaoguang and @jianjianxu ! I suppose the expected behaviour would be to redirect to the desired route in case he's logged in (in this case gitea.com/work/myjob/issues/15) I suspect the issue lies in services/auth/middleware.go: // Redirect to dashboard if user tries to visit any non-login page.
if options.SignOutRequired && ctx.IsSigned && ctx.Req.URL.RequestURI() != "/" {
ctx.Redirect(setting.AppSubURL + "/")
return
} This code redirects a logged-in user to the homepage if they try to access a route that requires sign-out. However, it doesn't consider the case where the user is trying to access the login page with a redirect_to parameter. I think I will modify the middleware to account for the redirect_to case. I'll make a PR if it solve the issue However, the checkAutoLogin function in routes/web/auth.go isn't being called. This function seems to handle the redirect_to paramater if user is signed in. Im new to codebase so I dont know if there's specific cases where it is suppose to get called func checkAutoLogin(ctx *context.Context) bool {
// Check auto-login
isSucceed, err := AutoSignIn(ctx)
if err != nil {
ctx.ServerError("AutoSignIn", err)
return true
}
redirectTo := ctx.FormString("redirect_to")
if len(redirectTo) > 0 {
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
} else {
redirectTo = ctx.GetSiteCookie("redirect_to")
}
if isSucceed {
middleware.DeleteRedirectToCookie(ctx.Resp)
ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL))
return true
}
return false
} |
This PR addresses an issue where logged-in users get redirected to the homepage when trying to access a URL with the redirect_to parameter. The issue was traced back to a middleware function in services/auth/middleware.go that redirects logged-in users to the homepage. This function didn't account the redirect_to parameter. The fix modifies the middleware function to check for this case and redirect the user to the specified URL instead of the homepage. Closes: #26005 --------- Signed-off-by: cassiozareck <cassiomilczareck@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Many thanks to @cassiozareck for addressing the problem. @jianjianxu could you try it on try.gitea.io (eg: https://try.gitea.io/user/login?redirect_to=/issues ) to see whether #26105 works? I made some changes there because it seems that the "POST" method is not a must for this issue. |
Feature Description
When I am not logged in, I open the webpage "https://gitea.com/user/login?redirect_to=https://gitea.com/work/myjob/issues/15", after logging in, it will redirect normally.
But, when I am already logged in, I open the webpage "https://gitea.com/user/login?redirect_to=https://gitea.com/work/myjob/issues/15", after logging in, I will be redirected to the homepage.
Screenshots
No response
The text was updated successfully, but these errors were encountered: