Skip to content

Commit 2fbdfb4

Browse files
committed
fix: remove default maxAgeInSeconds in emailverification claim
1 parent 966a65a commit 2fbdfb4

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.23.0] - 2024-07-10
11+
12+
### Breaking Changes
13+
14+
- Removes the default `maxAgeInSeconds` value (previously 300 seconds) in EmailVerification Claim. If the claim value is true and `maxAgeInSeconds` is not provided, it will not be refetched.
15+
1016
## [0.22.1] - 2024-07-09
1117

1218
### Changes

recipe/emailverification/emailverificationClaim.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func NewEmailVerificationClaim() (*claims.TypeSessionClaim, evclaims.TypeEmailVe
3434
}
3535
}
3636

37-
var defaultMaxAge int64 = 300
38-
evClaim, booleanClaimValidators := claims.BooleanClaim("st-ev", fetchValue, &defaultMaxAge)
37+
evClaim, booleanClaimValidators := claims.BooleanClaim("st-ev", fetchValue, nil)
3938

4039
getLastRefetchTime := func(payload map[string]interface{}, userContext supertokens.UserContext) *int64 {
4140
if value, ok := payload[evClaim.Key].(map[string]interface{}); ok {
@@ -57,15 +56,31 @@ func NewEmailVerificationClaim() (*claims.TypeSessionClaim, evclaims.TypeEmailVe
5756
var defaultTimeout int64 = 10
5857
refetchTimeOnFalseInSeconds = &defaultTimeout
5958
}
60-
if maxAgeInSeconds == nil {
61-
var defaultTimeout int64 = 300
62-
maxAgeInSeconds = &defaultTimeout
63-
}
6459

6560
claimValidator := booleanClaimValidators.HasValue(true, maxAgeInSeconds, nil)
6661
claimValidator.ShouldRefetch = func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
6762
value := evClaim.GetValueFromPayload(payload, userContext)
68-
return value == nil || (*getLastRefetchTime(payload, userContext) < time.Now().UnixNano()/1000000-*maxAgeInSeconds*1000) || (value == false && *getLastRefetchTime(payload, userContext) < time.Now().UnixNano()/1000000-*refetchTimeOnFalseInSeconds*1000)
63+
64+
if value == nil {
65+
return true
66+
}
67+
68+
currentTime := time.Now().UnixNano() / 1000000
69+
lastRefetchTime := getLastRefetchTime(payload, userContext)
70+
71+
if maxAgeInSeconds != nil {
72+
if lastRefetchTime != nil && *lastRefetchTime < currentTime-*maxAgeInSeconds*1000 {
73+
return true
74+
}
75+
}
76+
77+
if value == false {
78+
if lastRefetchTime != nil && *lastRefetchTime < currentTime-*refetchTimeOnFalseInSeconds*1000 {
79+
return true
80+
}
81+
}
82+
83+
return false
6984
}
7085
return claimValidator
7186
},

supertokens/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
// VERSION current version of the lib
24-
const VERSION = "0.22.1"
24+
const VERSION = "0.23.0"
2525

2626
var (
2727
cdiSupported = []string{"3.0"}

0 commit comments

Comments
 (0)