@@ -34,13 +34,20 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
3434
3535 sessionClaim .GetValueFromPayload = func (payload map [string ]interface {}, userContext supertokens.UserContext ) interface {} {
3636 if value , ok := payload [sessionClaim .Key ].(map [string ]interface {}); ok {
37+ return value
38+ }
39+ return nil
40+ }
41+
42+ getValueFromPayload := func (payload map [string ]interface {}, userContext supertokens.UserContext ) interface {} {
43+ if value , ok := sessionClaim .GetValueFromPayload (payload , userContext ).(map [string ]interface {}); ok {
3744 return value ["v" ]
3845 }
3946 return nil
4047 }
4148
42- sessionClaim . GetLastRefetchTime = func (payload map [string ]interface {}, userContext supertokens.UserContext ) * int64 {
43- if value , ok := payload [ sessionClaim .Key ] .(map [string ]interface {}); ok {
49+ getLastRefetchTime : = func (payload map [string ]interface {}, userContext supertokens.UserContext ) * int64 {
50+ if value , ok := sessionClaim .GetValueFromPayload ( payload , userContext ) .(map [string ]interface {}); ok {
4451 val := value ["t" ].(int64 )
4552 return & val
4653 }
@@ -60,17 +67,17 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
6067 ID : claimId ,
6168 Claim : & sessionClaim ,
6269 ShouldRefetch : func (payload map [string ]interface {}, userContext supertokens.UserContext ) bool {
63- claimVal , ok := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
70+ claimVal , ok := getValueFromPayload (payload , userContext ).([]interface {})
6471 if ! ok || claimVal == nil {
6572 return true
6673 }
6774 if maxAgeInSeconds != nil {
68- return * sessionClaim . GetLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
75+ return * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
6976 }
7077 return false
7178 },
7279 Validate : func (payload map [string ]interface {}, userContext supertokens.UserContext ) ClaimValidationResult {
73- claimVal := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
80+ claimVal := getValueFromPayload (payload , userContext ).([]interface {})
7481
7582 if claimVal == nil {
7683 return ClaimValidationResult {
@@ -82,7 +89,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
8289 },
8390 }
8491 }
85- ageInSeconds := (time .Now ().UnixMilli () - * sessionClaim . GetLastRefetchTime (payload , userContext )) / 1000
92+ ageInSeconds := (time .Now ().UnixMilli () - * getLastRefetchTime (payload , userContext )) / 1000
8693 if maxAgeInSeconds != nil && ageInSeconds > * maxAgeInSeconds {
8794 return ClaimValidationResult {
8895 IsValid : false ,
@@ -121,17 +128,17 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
121128 ID : claimId ,
122129 Claim : & sessionClaim ,
123130 ShouldRefetch : func (payload map [string ]interface {}, userContext supertokens.UserContext ) bool {
124- val , ok := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
131+ val , ok := getValueFromPayload (payload , userContext ).([]interface {})
125132 if ! ok || val == nil {
126133 return true
127134 }
128135 if maxAgeInSeconds != nil {
129- return * sessionClaim . GetLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
136+ return * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
130137 }
131138 return false
132139 },
133140 Validate : func (payload map [string ]interface {}, userContext supertokens.UserContext ) ClaimValidationResult {
134- claimVal := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
141+ claimVal := getValueFromPayload (payload , userContext ).([]interface {})
135142
136143 if claimVal == nil {
137144 return ClaimValidationResult {
@@ -143,7 +150,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
143150 },
144151 }
145152 }
146- ageInSeconds := (time .Now ().UnixMilli () - * sessionClaim . GetLastRefetchTime (payload , userContext )) / 1000
153+ ageInSeconds := (time .Now ().UnixMilli () - * getLastRefetchTime (payload , userContext )) / 1000
147154 if maxAgeInSeconds != nil && ageInSeconds > * maxAgeInSeconds {
148155 return ClaimValidationResult {
149156 IsValid : false ,
@@ -182,17 +189,17 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
182189 ID : claimId ,
183190 Claim : & sessionClaim ,
184191 ShouldRefetch : func (payload map [string ]interface {}, userContext supertokens.UserContext ) bool {
185- val , ok := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
192+ val , ok := getValueFromPayload (payload , userContext ).([]interface {})
186193 if ! ok || val == nil {
187194 return true
188195 }
189196 if maxAgeInSeconds != nil {
190- return * sessionClaim . GetLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
197+ return * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
191198 }
192199 return false
193200 },
194201 Validate : func (payload map [string ]interface {}, userContext supertokens.UserContext ) ClaimValidationResult {
195- claimVal := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
202+ claimVal := getValueFromPayload (payload , userContext ).([]interface {})
196203
197204 if claimVal == nil {
198205 return ClaimValidationResult {
@@ -204,7 +211,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
204211 },
205212 }
206213 }
207- ageInSeconds := (time .Now ().UnixMilli () - * sessionClaim . GetLastRefetchTime (payload , userContext )) / 1000
214+ ageInSeconds := (time .Now ().UnixMilli () - * getLastRefetchTime (payload , userContext )) / 1000
208215 if maxAgeInSeconds != nil && ageInSeconds > * maxAgeInSeconds {
209216 return ClaimValidationResult {
210217 IsValid : false ,
@@ -244,17 +251,17 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
244251 ID : claimId ,
245252 Claim : & sessionClaim ,
246253 ShouldRefetch : func (payload map [string ]interface {}, userContext supertokens.UserContext ) bool {
247- val , ok := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
254+ val , ok := getValueFromPayload (payload , userContext ).([]interface {})
248255 if ! ok || val == nil {
249256 return true
250257 }
251258 if maxAgeInSeconds != nil {
252- return * sessionClaim . GetLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
259+ return * getLastRefetchTime (payload , userContext ) < time .Now ().UnixMilli ()- * maxAgeInSeconds * 1000
253260 }
254261 return false
255262 },
256263 Validate : func (payload map [string ]interface {}, userContext supertokens.UserContext ) ClaimValidationResult {
257- claimVal := sessionClaim . GetValueFromPayload (payload , userContext ).([]interface {})
264+ claimVal := getValueFromPayload (payload , userContext ).([]interface {})
258265
259266 if claimVal == nil {
260267 return ClaimValidationResult {
@@ -266,7 +273,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
266273 },
267274 }
268275 }
269- ageInSeconds := (time .Now ().UnixMilli () - * sessionClaim . GetLastRefetchTime (payload , userContext )) / 1000
276+ ageInSeconds := (time .Now ().UnixMilli () - * getLastRefetchTime (payload , userContext )) / 1000
270277 if maxAgeInSeconds != nil && ageInSeconds > * maxAgeInSeconds {
271278 return ClaimValidationResult {
272279 IsValid : false ,
0 commit comments