feat: initial router on main function
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
jwtclaimenum "github.com/ardeman/project-legalgo-go/internal/enums/jwt"
|
||||
timeutils "github.com/ardeman/project-legalgo-go/internal/utilities/time_utils"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
@@ -25,3 +27,13 @@ func GenerateToken(options ...ClaimOption) (string, error) {
|
||||
|
||||
return token.SignedString(jwtSecret)
|
||||
}
|
||||
|
||||
func GenerateToken2(username string) (string, error) {
|
||||
now := timeutils.Now()
|
||||
token := jwt.New(jwt.SigningMethodES256)
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
claims["username"] = username
|
||||
claims["exp"] = now.Add(time.Hour).Unix()
|
||||
|
||||
return token.SignedString(jwtSecret)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func StoreToken(ctx context.Context, rdb *redis.Client, token, username string) error {
|
||||
// return rdb.Set(ctx context.Context, key string, value interface{}, expiration time.Duration)
|
||||
return rdb.Set(ctx, "token"+username, token, time.Hour).Err()
|
||||
}
|
||||
Reference in New Issue
Block a user