add cache for groups and clients, http sending message remains to be add
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
_ "github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
var secretKey = []byte("replace-with-env-variable")
|
||||
@@ -22,7 +21,7 @@ func GetToken(user *User) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256,
|
||||
UserClaims{
|
||||
Name: user.Name,
|
||||
Color: user.Color,
|
||||
Color: string(user.Color[:]),
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
Subject: strconv.Itoa(int(user.Id)),
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour)),
|
||||
@@ -54,9 +53,11 @@ func GetUserFromToken(tokenString string) (User, error) {
|
||||
return User{}, fmt.Errorf("invalid subject: %w", err)
|
||||
}
|
||||
|
||||
var color [3]byte
|
||||
copy(color[:], claims.Color)
|
||||
return User{
|
||||
Id: uint32(id),
|
||||
Name: claims.Name,
|
||||
Color: claims.Color,
|
||||
Color: color,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user