Skip to content

Commit ad1b463

Browse files
committed
fix: getclaimvalue
1 parent d861f18 commit ad1b463

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

recipe/emailverification/api/implementation.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,13 @@ func MakeAPIImplementation() evmodels.APIInterface {
5959
return evmodels.IsEmailVerifiedGETResponse{}, err
6060
}
6161

62-
var isVerified bool = false
63-
if isVerifiedVal, ok := sessionContainer.GetClaimValueWithContext(evclaims.EmailVerificationClaim, userContext).(map[string]interface{}); ok {
64-
isVerified, ok = isVerifiedVal["v"].(bool)
65-
if !ok {
66-
return evmodels.IsEmailVerifiedGETResponse{}, errors.New("should never come here: EmailVerificationClaim failed to set value")
67-
}
68-
} else {
62+
isVerified := sessionContainer.GetClaimValueWithContext(evclaims.EmailVerificationClaim, userContext)
63+
if isVerified == nil {
6964
return evmodels.IsEmailVerifiedGETResponse{}, errors.New("should never come here: EmailVerificationClaim failed to set value")
7065
}
71-
7266
return evmodels.IsEmailVerifiedGETResponse{
7367
OK: &struct{ IsVerified bool }{
74-
IsVerified: isVerified,
68+
IsVerified: isVerified.(bool),
7569
},
7670
}, nil
7771
}

recipe/session/claims/primitiveArrayClaim.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,13 @@ 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 {
4437
return value["v"]
4538
}
4639
return nil
4740
}
4841

4942
getLastRefetchTime := func(payload map[string]interface{}, userContext supertokens.UserContext) *int64 {
50-
if value, ok := sessionClaim.GetValueFromPayload(payload, userContext).(map[string]interface{}); ok {
43+
if value, ok := payload[sessionClaim.Key].(map[string]interface{}); ok {
5144
val := value["t"].(int64)
5245
return &val
5346
}
@@ -67,7 +60,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
6760
ID: claimId,
6861
Claim: sessionClaim,
6962
ShouldRefetch: func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
70-
claimVal, ok := getValueFromPayload(payload, userContext).([]interface{})
63+
claimVal, ok := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
7164
if !ok || claimVal == nil {
7265
return true
7366
}
@@ -77,7 +70,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
7770
return false
7871
},
7972
Validate: func(payload map[string]interface{}, userContext supertokens.UserContext) ClaimValidationResult {
80-
claimVal := getValueFromPayload(payload, userContext).([]interface{})
73+
claimVal := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
8174

8275
if claimVal == nil {
8376
return ClaimValidationResult{
@@ -128,7 +121,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
128121
ID: claimId,
129122
Claim: sessionClaim,
130123
ShouldRefetch: func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
131-
val, ok := getValueFromPayload(payload, userContext).([]interface{})
124+
val, ok := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
132125
if !ok || val == nil {
133126
return true
134127
}
@@ -138,7 +131,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
138131
return false
139132
},
140133
Validate: func(payload map[string]interface{}, userContext supertokens.UserContext) ClaimValidationResult {
141-
claimVal := getValueFromPayload(payload, userContext).([]interface{})
134+
claimVal := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
142135

143136
if claimVal == nil {
144137
return ClaimValidationResult{
@@ -189,7 +182,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
189182
ID: claimId,
190183
Claim: sessionClaim,
191184
ShouldRefetch: func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
192-
val, ok := getValueFromPayload(payload, userContext).([]interface{})
185+
val, ok := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
193186
if !ok || val == nil {
194187
return true
195188
}
@@ -199,7 +192,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
199192
return false
200193
},
201194
Validate: func(payload map[string]interface{}, userContext supertokens.UserContext) ClaimValidationResult {
202-
claimVal := getValueFromPayload(payload, userContext).([]interface{})
195+
claimVal := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
203196

204197
if claimVal == nil {
205198
return ClaimValidationResult{
@@ -251,7 +244,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
251244
ID: claimId,
252245
Claim: sessionClaim,
253246
ShouldRefetch: func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
254-
val, ok := getValueFromPayload(payload, userContext).([]interface{})
247+
val, ok := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
255248
if !ok || val == nil {
256249
return true
257250
}
@@ -261,7 +254,7 @@ func PrimitiveArrayClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInS
261254
return false
262255
},
263256
Validate: func(payload map[string]interface{}, userContext supertokens.UserContext) ClaimValidationResult {
264-
claimVal := getValueFromPayload(payload, userContext).([]interface{})
257+
claimVal := sessionClaim.GetValueFromPayload(payload, userContext).([]interface{})
265258

266259
if claimVal == nil {
267260
return ClaimValidationResult{

recipe/session/claims/primitiveClaim.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,13 @@ func PrimitiveClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInSecond
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 {
4437
return value["v"]
4538
}
4639
return nil
4740
}
4841

4942
getLastRefetchTime := func(payload map[string]interface{}, userContext supertokens.UserContext) *int64 {
50-
if value, ok := sessionClaim.GetValueFromPayload(payload, userContext).(map[string]interface{}); ok {
43+
if value, ok := payload[sessionClaim.Key].(map[string]interface{}); ok {
5144
val := value["t"].(int64)
5245
return &val
5346
}
@@ -67,14 +60,14 @@ func PrimitiveClaim(key string, fetchValue FetchValueFunc, defaultMaxAgeInSecond
6760
ID: validatorId,
6861
Claim: sessionClaim,
6962
ShouldRefetch: func(payload map[string]interface{}, userContext supertokens.UserContext) bool {
70-
val := getValueFromPayload(payload, userContext)
63+
val := sessionClaim.GetValueFromPayload(payload, userContext)
7164
if val == nil {
7265
return true
7366
}
7467
return maxAgeInSeconds != nil && *getLastRefetchTime(payload, userContext) < time.Now().UnixMilli()-*maxAgeInSeconds*1000
7568
},
7669
Validate: func(payload map[string]interface{}, userContext supertokens.UserContext) ClaimValidationResult {
77-
claimVal := getValueFromPayload(payload, userContext)
70+
claimVal := sessionClaim.GetValueFromPayload(payload, userContext)
7871

7972
if claimVal == nil {
8073
return ClaimValidationResult{

0 commit comments

Comments
 (0)