From aa4c6406d11b994278e3b25c5407feb671ec80a0 Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Tue, 31 Dec 2024 10:34:45 +0100 Subject: [PATCH] fix: rootpath on redirect to login --- internal/http/response/shortcuts.go | 12 ++++++++++-- internal/http/routes/bookmark.go | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/http/response/shortcuts.go b/internal/http/response/shortcuts.go index ed614e543..d94936147 100644 --- a/internal/http/response/shortcuts.go +++ b/internal/http/response/shortcuts.go @@ -2,6 +2,7 @@ package response import ( "net/http" + "net/url" "github.com/gin-gonic/gin" ) @@ -35,10 +36,17 @@ func SendInternalServerError(ctx *gin.Context) { } // SendNotFound directly sends a not found response -func RedirectToLogin(ctx *gin.Context, dst string) { - ctx.Redirect(http.StatusFound, "/?dst="+dst) +func RedirectToLogin(ctx *gin.Context, webroot, dst string) { + url := url.URL{ + Path: webroot, + RawQuery: url.Values{ + "dst": []string{dst}, + }.Encode(), + } + ctx.Redirect(http.StatusFound, url.String()) } +// NotFound directly sends a not found response func NotFound(ctx *gin.Context) { ctx.AbortWithStatus(http.StatusNotFound) } diff --git a/internal/http/routes/bookmark.go b/internal/http/routes/bookmark.go index e0073dcdd..7a2c7e8a8 100644 --- a/internal/http/routes/bookmark.go +++ b/internal/http/routes/bookmark.go @@ -64,7 +64,7 @@ func (r *BookmarkRoutes) getBookmark(c *context.Context) (*model.BookmarkDTO, er } if bookmark.Public != 1 && !c.UserIsLogged() { - response.RedirectToLogin(c.Context, c.Request.URL.String()) + response.RedirectToLogin(c.Context, r.deps.Config.Http.RootPath, c.Request.URL.String()) return nil, model.ErrUnauthorized }