@@ -36,13 +36,6 @@ func NewEmailVerificationClaim() (*claims.TypeSessionClaim, evclaims.TypeEmailVe
3636
3737 evClaim , booleanClaimValidators := claims .BooleanClaim ("st-ev" , fetchValue , nil )
3838
39- getValueFromPayload := func (payload map [string ]interface {}, userContext supertokens.UserContext ) interface {} {
40- if value , ok := evClaim .GetValueFromPayload (payload , userContext ).(map [string ]interface {}); ok {
41- return value ["v" ]
42- }
43- return nil
44- }
45-
4639 getLastRefetchTime := func (payload map [string ]interface {}, userContext supertokens.UserContext ) * int64 {
4740 if value , ok := evClaim .GetValueFromPayload (payload , userContext ).(map [string ]interface {}); ok {
4841 val := value ["t" ].(int64 )
@@ -53,16 +46,20 @@ func NewEmailVerificationClaim() (*claims.TypeSessionClaim, evclaims.TypeEmailVe
5346
5447 validators := evclaims.TypeEmailVerificationClaimValidators {
5548 BooleanClaimValidators : booleanClaimValidators ,
56- IsVerified : func (refetchTimeOnFalseInSeconds * int64 ) claims.SessionClaimValidator {
49+ IsVerified : func (refetchTimeOnFalseInSeconds * int64 , maxAgeInSeconds * int64 ) claims.SessionClaimValidator {
5750 if refetchTimeOnFalseInSeconds == nil {
5851 var defaultTimeout int64 = 10
5952 refetchTimeOnFalseInSeconds = & defaultTimeout
6053 }
54+ if maxAgeInSeconds == nil {
55+ var defaultTimeout int64 = 300
56+ maxAgeInSeconds = & defaultTimeout
57+ }
6158
6259 claimValidator := booleanClaimValidators .HasValue (true , nil , nil )
6360 claimValidator .ShouldRefetch = func (payload map [string ]interface {}, userContext supertokens.UserContext ) bool {
64- value := getValueFromPayload (payload , userContext )
65- return value == nil || (value == false && * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * refetchTimeOnFalseInSeconds * 1000 )
61+ value := evClaim . GetValueFromPayload (payload , userContext )
62+ return value == nil || (* getLastRefetchTime ( payload , userContext ) < time . Now (). UnixMilli () - * maxAgeInSeconds * 1000 ) || ( value == false && * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * refetchTimeOnFalseInSeconds * 1000 )
6663 }
6764 return claimValidator
6865 },
0 commit comments