You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
558 B
Go

package jwtmanager
import (
"time"
"github.com/ajikamaludin/go-fiber-rest/app/configs"
"github.com/ajikamaludin/go-fiber-rest/app/models"
"github.com/golang-jwt/jwt/v4"
)
func CreateToken(user *models.User) string {
configs := configs.GetInstance()
claims := jwt.MapClaims{
"user_id": user.ID,
"exp": time.Now().Add(time.Duration(configs.Jwtconfig.Expired) * time.Second).Unix(),
}
unsignToken := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token, _ := unsignToken.SignedString([]byte(configs.Jwtconfig.Secret))
return token
}