code refactoring, fixed wrong jwt expire time

This commit is contained in:
2023-06-23 15:18:40 +02:00
parent 7d510fd2d4
commit 3067cee08c
5 changed files with 151 additions and 140 deletions

View File

@@ -160,8 +160,10 @@ func Login(ctx *fiber.Ctx) error {
return ctx.SendStatus(fiber.StatusBadRequest)
}
expiresAt := time.Now().Add(time.Hour * 24 * 30)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"expiresAt": time.Now().Add(time.Minute * 30),
"expiresAt": expiresAt,
})
tokenString, err := token.SignedString([]byte(os.Getenv("JWT_SECRET")))
@@ -173,7 +175,7 @@ func Login(ctx *fiber.Ctx) error {
Name: TOKEN_COOKIE_NAME,
HTTPOnly: true,
Secure: false,
Expires: time.Now().Add(time.Hour * 24 * 30), // 30 days
Expires: expiresAt, // 30 days
Value: tokenString,
Path: "/",
})