Skip to content

Commit

Permalink
fix: rootpath on redirect to login
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Dec 31, 2024
1 parent 1753fe9 commit aa4c640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions internal/http/response/shortcuts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package response

import (
"net/http"
"net/url"

"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion internal/http/routes/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit aa4c640

Please sign in to comment.