From 4ed24ab555c6548a91ec25b17fb3a37361b42ec5 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sat, 30 Nov 2024 16:36:22 +0200 Subject: [PATCH] Add tokens.SESSION_DURATION_IN_SECONDS to tokens package and made cookies sent to front and in db session duration to be in sync --- handlers/user.go | 4 ++-- tokens/sessions.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/handlers/user.go b/handlers/user.go index b55f036..19a6974 100644 --- a/handlers/user.go +++ b/handlers/user.go @@ -53,7 +53,7 @@ func UserRegister(c *gin.Context) { log.Printf("tokens.CreateSessionFromToken: %v\n", err) c.JSON(500, types.ErrorResponse{Message: "ERROR: 1000"}) } - c.SetCookie(consts.COOKIE_SESSION, token1.Val, 3600, "/", "localhost", false, true) + c.SetCookie(consts.COOKIE_SESSION, token1.Val, tokens.SESSION_DURATION_IN_SECONDS, "/", "localhost", false, true) acc := types.Account{ ID: dbUser.ID, Token: token1.Val, @@ -110,7 +110,7 @@ func UserLogin(c *gin.Context) { log.Printf("tokens.CreateSessionFromToken: %v\n", err) c.JSON(500, types.ErrorResponse{Message: "ERROR: 1000"}) } - c.SetCookie(consts.COOKIE_SESSION, token1.Val, 3600, "/", "localhost", false, true) + c.SetCookie(consts.COOKIE_SESSION, token1.Val, tokens.SESSION_DURATION_IN_SECONDS, "/", "localhost", false, true) acc := types.Account{ ID: foundUser.ID, Token: token1.Val, diff --git a/tokens/sessions.go b/tokens/sessions.go index 7219503..2f4f518 100644 --- a/tokens/sessions.go +++ b/tokens/sessions.go @@ -10,7 +10,8 @@ import ( "git.qowevisa.me/Qowevisa/fin-check-api/db" ) -const SESSION_DURATION = (24 * time.Hour) +const SESSION_DURATION_IN_SECONDS = 3600 +const SESSION_DURATION = (SESSION_DURATION_IN_SECONDS * time.Second) func CreateSessionFromToken(token string, userID uint) error { sessionID := getSessionIDFromToken(token)