fix token issue

This commit is contained in:
behrooz
2025-08-15 18:23:50 +03:30
parent 244be8ea85
commit 720e6914fb
2 changed files with 52 additions and 18 deletions

View File

@@ -69,7 +69,7 @@ func Human(d time.Duration) string {
var jwtKey = []byte("mysecret123")
func DecodeJwt(tokenString *string, user *models.User) {
func DecodeJwt(tokenString *string, user *models.User) error {
claims := jwt.MapClaims{}
_, err := jwt.ParseWithClaims(*tokenString, claims, func(token *jwt.Token) (interface{}, error) {
return []byte(jwtKey), nil
@@ -77,10 +77,11 @@ func DecodeJwt(tokenString *string, user *models.User) {
if err != nil {
log.Println(err)
return
return err
}
user.Username = claims["username"].(string)
return nil
}
func ValidateUser(user string) error {