api/pkg/utils/userUuid.go

49 lines
1 KiB
Go
Raw Permalink Normal View History

2025-07-06 22:21:32 +03:00
package utils
import (
"errors"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
func (u *Utils) GetUserUuidFromContext(c *gin.Context) (string, error) {
if c == nil {
return "", errors.New("context is nil")
}
uuidRaw, exists := c.Get("userUuid")
if !exists {
return "", errors.New("user uuid not found in context")
}
userUuidStr, ok := uuidRaw.(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")
}
return userUuid.String(), nil
}
2025-09-14 19:32:22 +03:00
func (u *Utils) GetRefreshUuidFromContext(c *gin.Context) (string, error) {
refreshRaw, exists := c.Get("refresh_uuid")
if !exists {
return "", errors.New("refresh_uuid not found in context")
}
refreshUuidStr, ok := refreshRaw.(string)
if !ok {
return "", errors.New("refresh_uuid is not a string")
}
refreshUuid, err := uuid.Parse(refreshUuidStr)
if err != nil {
return "", errors.New("error parsing refresh_uuid")
}
return refreshUuid.String(), nil
}