Skip to content

Commit

Permalink
Fixed lost lang parameter in certain routes
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored Jun 4, 2024
1 parent f79a2e0 commit 6c30efa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/webserver/controller/auth/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (a *Controller) SignIn(c *fiber.Ctx) error {
Name: "coreander",
Value: signedToken,
Path: "/",
Expires: expiration,
MaxAge: int(a.config.SessionTimeout.Seconds()),
Secure: false,
HTTPOnly: true,
})
Expand Down
5 changes: 2 additions & 3 deletions internal/webserver/controller/auth/signout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auth

import (
"fmt"
"time"

"github.com/gofiber/fiber/v2"
)
Expand All @@ -11,9 +10,9 @@ import (
func (a *Controller) SignOut(c *fiber.Ctx) error {
c.Cookie(&fiber.Cookie{
Name: "coreander",
Value: "",
Value: "void",
Path: "/",
Expires: time.Now().Add(-time.Second * 10),
MaxAge: -1,
Secure: false,
HTTPOnly: true,
})
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/controller/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (u *Controller) updateUserData(c *fiber.Ctx, user *model.User, session mode
Name: "coreander",
Value: signedToken,
Path: "/",
Expires: expiration,
MaxAge: int(session.Exp),
Secure: false,
HTTPOnly: true,
})
Expand Down
3 changes: 1 addition & 2 deletions internal/webserver/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ func forbidden(c *fiber.Ctx, sender Sender, err error) error {
emailSendingConfigured = false
}
message := ""
if err.Error() != "missing or malformed JWT" {
if err.Error() != "missing or malformed JWT" && c.Cookies("coreander") != "void" {
message = "Session expired, please log in again."
}

return c.Status(fiber.StatusForbidden).Render("auth/login", fiber.Map{
"Lang": chooseBestLanguage(c),
"Title": "Login",
Expand Down
1 change: 1 addition & 0 deletions internal/webserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func routes(app *fiber.App, controllers Controllers, jwtSecret []byte, sender Se
langGroup.Get("/logout", alwaysRequireAuthentication, controllers.Auth.SignOut)

// Authentication requirement is configurable for all routes below this middleware
langGroup.Use(configurableAuthentication)
app.Use(configurableAuthentication)

app.Get("/cover/:slug", controllers.Documents.Cover)
Expand Down

0 comments on commit 6c30efa

Please sign in to comment.