Add tokens.SESSION_DURATION_IN_SECONDS to tokens package and made cookies sent to front and in db session duration to be in sync

This commit is contained in:
qowevisa 2024-11-30 16:36:22 +02:00
parent 39275473af
commit 4ed24ab555
2 changed files with 4 additions and 3 deletions

View File

@ -53,7 +53,7 @@ func UserRegister(c *gin.Context) {
log.Printf("tokens.CreateSessionFromToken: %v\n", err) log.Printf("tokens.CreateSessionFromToken: %v\n", err)
c.JSON(500, types.ErrorResponse{Message: "ERROR: 1000"}) 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{ acc := types.Account{
ID: dbUser.ID, ID: dbUser.ID,
Token: token1.Val, Token: token1.Val,
@ -110,7 +110,7 @@ func UserLogin(c *gin.Context) {
log.Printf("tokens.CreateSessionFromToken: %v\n", err) log.Printf("tokens.CreateSessionFromToken: %v\n", err)
c.JSON(500, types.ErrorResponse{Message: "ERROR: 1000"}) 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{ acc := types.Account{
ID: foundUser.ID, ID: foundUser.ID,
Token: token1.Val, Token: token1.Val,

View File

@ -10,7 +10,8 @@ import (
"git.qowevisa.me/Qowevisa/fin-check-api/db" "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 { func CreateSessionFromToken(token string, userID uint) error {
sessionID := getSessionIDFromToken(token) sessionID := getSessionIDFromToken(token)