Skip to content

cannot compare refreshClaims.ExpiresAt < time.Now().Unix() (operator < not defined for *jwt.NumericDate) #145

Answered by oxisto
raliqala asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately Go does not allow to overload operators, so you cannot use > to compare the jwt.NumericDate with seconds or another time. You can however use the function VerifyExpiresAt which will abstract this for you:

currentDate = time.Now()
if !refreshClaims.VerifyExpiresAt(currentDate, true) {
 /* token is expired */
}

Note: in your example, the first if token.Valid should probably be if !token.Valid because if the token is valid, it can never be expired (in our current system, unless you have override this behaviour somehow).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@raliqala
Comment options

Answer selected by oxisto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #144 on December 27, 2021 12:27.