added: get refresh token uuid from jwt method
This commit is contained in:
parent
7e0c1e71de
commit
0a53ac2974
2 changed files with 41 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue