From 0a53ac2974ff5007c152d5688c4a38beee3da20e Mon Sep 17 00:00:00 2001 From: nquidox Date: Mon, 7 Jul 2025 17:48:01 +0300 Subject: [PATCH] added: get refresh token uuid from jwt method --- internal/interfaces/utils.go | 1 + pkg/utils/userUuid.go | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/internal/interfaces/utils.go b/internal/interfaces/utils.go index d7c06b5..d1b8f7c 100644 --- a/internal/interfaces/utils.go +++ b/internal/interfaces/utils.go @@ -5,6 +5,7 @@ import "github.com/gin-gonic/gin" type Utils interface { IsEmail(email string) bool GetUserUuidFromContext(c *gin.Context) (string, error) + GetUserAndTokenUuidFromContext(c *gin.Context) (string, string, error) HashPassword(password string) (string, error) ComparePasswords(hashedPassword string, plainPassword string) error } diff --git a/pkg/utils/userUuid.go b/pkg/utils/userUuid.go index ae24ce6..1f1c867 100644 --- a/pkg/utils/userUuid.go +++ b/pkg/utils/userUuid.go @@ -27,3 +27,43 @@ func (u *Utils) GetUserUuidFromContext(c *gin.Context) (string, error) { } return userUuid.String(), nil } + +func (u *Utils) GetUserAndTokenUuidFromContext(c *gin.Context) (string, string, error) { + if c == nil { + return "", "", errors.New("context is nil") + } + + //get user uuid + userRaw, exists := c.Get("userUuid") + if !exists { + return "", "", errors.New("user uuid not found in context") + } + + userUuidStr, ok := userRaw.(string) + if !ok { + return "", "", errors.New("user uuid is not a string") + } + + userUuid, err := uuid.Parse(userUuidStr) + if err != nil { + return "", "", errors.New("error parsing user uuid") + } + + //get refresh token uuid + refreshRaw, exists := c.Get("refreshUuid") + if !exists { + return "", "", errors.New("user uuid not found in context") + } + + refreshUuidStr, ok := refreshRaw.(string) + if !ok { + return "", "", errors.New("user uuid is not a string") + } + + refreshUuid, err := uuid.Parse(refreshUuidStr) + if err != nil { + return "", "", errors.New("error parsing user uuid") + } + + return userUuid.String(), refreshUuid.String(), nil +}