🐛 Trying to fix reply token
This commit is contained in:
parent
3000b9d1a3
commit
52f839ba9a
@ -1,6 +1,7 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ func CreateReplyToken(eventId uint, userId uint) (string, error) {
|
|||||||
EventID: eventId,
|
EventID: eventId,
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
Issuer: "messaging",
|
Issuer: "messaging",
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 7)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 30)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +42,17 @@ func ParseReplyToken(tk string) (ReplyClaims, error) {
|
|||||||
return []byte(viper.GetString("security.reply_token_secret")), nil
|
return []byte(viper.GetString("security.reply_token_secret")), nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Check if the error is an expired token error
|
||||||
|
if errors.Is(err, jwt.ErrTokenExpired) {
|
||||||
|
// Treat expired token as valid (allow it)
|
||||||
|
return claims, nil
|
||||||
|
}
|
||||||
return claims, err
|
return claims, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !token.Valid {
|
if !token.Valid {
|
||||||
return claims, fmt.Errorf("invalid token")
|
return claims, fmt.Errorf("invalid token")
|
||||||
}
|
}
|
||||||
|
|
||||||
return claims, nil
|
return claims, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user