diff --git a/logic/user.go b/logic/user.go index 5694afc315d12af7387c72a9713349aacea63a33..bb5912f39cdf46a653ca6152beb15187d20af1a5 100644 --- a/logic/user.go +++ b/logic/user.go @@ -162,10 +162,11 @@ func (ul *UserLogic) Login(u models.User) ( // Create a new JSON Web Token with HS256 method token := jwt.New(jwt.SigningMethodHS256) - token.Claims["userId"] = user.Id + claims := token.Claims.(jwt.MapClaims) + claims["userId"] = user.Id // Set the expiration for the token - token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix() + claims["exp"] = time.Now().Add(time.Hour * 72).Unix() // Sign the token with the secret key tokenStr, err := token.SignedString(ul.jwtSecret) @@ -199,9 +200,10 @@ func (ul *UserLogic) AuthWithJWT(token string) (*models.User, error) { return nil, AuthErrTokenNotValid } + claims := jwtToken.Claims.(jwt.MapClaims) // The userid should always be in the token claims if the token // is valid - userId, ok := jwtToken.Claims["userId"].(string) + userId, ok := claims["userId"].(string) if !ok { return nil, errors.New("Unexpected server error")