How do I know if the token is expired or other errors? #133
-
I have a requirement, if it is expired, I want to return a new token, other errors will continue to make mistakes |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
please A help |
Beta Was this translation helpful? Give feedback.
-
jwtToken.Valid return if token is valid or not |
Beta Was this translation helpful? Give feedback.
-
You need to access our specific error type var ve *jwt.ValidationError
if errors.As(err, &ve) {
if ve.Errors&jwt.ValidationErrorExpired != 0 {
// Token is either expired or not active yet
fmt.Println("Timing is everything")
}
} Similar code can be found in the error checking example Lines 96 to 119 in c435f38 |
Beta Was this translation helpful? Give feedback.
You need to access our specific error type
ValidationError
and then can access the bit mask to get the type of error. We are working to improve this. The first step is to support error unwrapping with #125 but this does not work consistently for all claims yet. So you need to do the following, iferr
is the error you get fromParse
orParseWithClaims
.Similar code can be found in the error checking example
jwt/example_test.go
Lines 96 to 119 in c435f38