Skip to content

Commit 2dca9c0

Browse files
committed
refactor:remaining changes
1 parent 28392ee commit 2dca9c0

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

supertokens_python/recipe/emailverification/ev_claim.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ def __init__(
3333
claim: BooleanClaim,
3434
has_value_validator: SessionClaimValidator,
3535
refetch_time_on_false_in_seconds: int,
36+
max_age_in_seconds: int,
3637
):
3738
super().__init__("st-ev-is-verified")
3839
self.claim: BooleanClaim = claim # TODO: Should work without specifying type of self.claim (no pyright errors)
3940
self.has_value_validator = has_value_validator
4041
self.refetch_time_on_false_in_ms = refetch_time_on_false_in_seconds * 1000
42+
self.max_age_in_ms = max_age_in_seconds * 1000
4143

4244
async def validate(
4345
self, payload: JSONObject, user_context: Dict[str, Any]
@@ -50,21 +52,31 @@ def should_refetch(
5052
value = self.claim.get_value_from_payload(payload, user_context)
5153
last_refetch_time = self.claim.get_last_refetch_time(payload, user_context)
5254
assert last_refetch_time is not None
53-
return (value is None) or (
54-
value is False
55-
and last_refetch_time
56-
< (
57-
get_timestamp_ms() - self.refetch_time_on_false_in_ms
58-
) # TODO: Default 5 min?
55+
56+
return (
57+
(value is None)
58+
or (last_refetch_time < get_timestamp_ms() - self.max_age_in_ms)
59+
or (
60+
value is False
61+
and last_refetch_time
62+
< (
63+
get_timestamp_ms() - self.refetch_time_on_false_in_ms
64+
) # TODO: Default 5 min?
65+
)
5966
)
6067

6168

6269
class EmailVerificationClaimValidators(BooleanClaimValidators):
6370
def is_verified(
64-
self, refetch_time_on_false_in_seconds: int = 10
71+
self,
72+
refetch_time_on_false_in_seconds: int = 10,
73+
max_age_in_seconds: int = 300,
6574
) -> SessionClaimValidator:
6675
has_value_res = self.has_value(True, id_="st-ev-is-verified")
6776
assert isinstance(self.claim, BooleanClaim)
6877
return IsVerifiedSCV(
69-
self.claim, has_value_res, refetch_time_on_false_in_seconds
78+
self.claim,
79+
has_value_res,
80+
refetch_time_on_false_in_seconds,
81+
max_age_in_seconds,
7082
)

supertokens_python/recipe/session/claim_base_classes/primitive_array_claim.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ async def _validate(
100100

101101
# Doing this to ensure same code in the upcoming steps irrespective of
102102
# whether self.val is Primitive or PrimitiveList
103-
vals: List[JSONPrimitive] = val if isinstance(val, list) else [val]
103+
vals: List[JSONPrimitive] = (
104+
val if isinstance(val, list) else [val]
105+
) # pyright: reportGeneralTypeIssues=false
106+
107+
#
104108

105109
claim_val_set = set(claim_val)
106110
if is_include:
@@ -176,7 +180,7 @@ def __init__(
176180

177181
def includes( # pyright: ignore[reportInvalidTypeVarUse]
178182
self,
179-
val: Primitive,
183+
val: Primitive, # pyright: ignore[reportInvalidTypeVarUse]
180184
id_: Union[str, None] = None,
181185
max_age_in_seconds: Optional[int] = None,
182186
) -> SessionClaimValidator:
@@ -187,7 +191,7 @@ def includes( # pyright: ignore[reportInvalidTypeVarUse]
187191

188192
def excludes( # pyright: ignore[reportInvalidTypeVarUse]
189193
self,
190-
val: Primitive,
194+
val: Primitive, # pyright: ignore[reportInvalidTypeVarUse]
191195
id_: Union[str, None] = None,
192196
max_age_in_seconds: Optional[int] = None,
193197
) -> SessionClaimValidator:

supertokens_python/recipe/session/claim_base_classes/primitive_claim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def __init__(
3939
super().__init__(id_)
4040
self.claim: SessionClaim[_T] = claim # Required to fix the type for pyright
4141
self.val = val
42-
self.max_age_in_sec = max_age_in_sec # TODO: Default 5 min
42+
self.max_age_in_sec = max_age_in_sec or 300
4343

4444
def should_refetch(
4545
self,
4646
payload: JSONObject,
4747
user_context: Dict[str, Any],
48-
):
49-
max_age_in_sec: int = self.max_age_in_sec
48+
) -> bool:
49+
max_age_in_sec = self.max_age_in_sec
5050

5151
# (claim value is None) OR (value has expired)
5252
return (self.claim.get_value_from_payload(payload, user_context) is None) or (

tests/auth-react/django3x/mysite/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ async def signout_post(
592592
"body", api_options.request
593593
)
594594
if is_general_error:
595-
return GeneralErrorResponse("general error from signout API")
595+
raise Exception("general error from signout API")
596596
return await original_signout_post(api_options, session, user_context)
597597

598598
original_implementation.signout_post = signout_post

tests/auth-react/fastapi-server/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ async def signout_post(
644644
"body", api_options.request
645645
)
646646
if is_general_error:
647-
return GeneralErrorResponse("general error from signout API")
647+
raise Exception("general error from signout API")
648648
return await original_signout_post(api_options, session, user_context)
649649

650650
original_implementation.signout_post = signout_post

tests/auth-react/flask-server/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ async def signout_post(
614614
"body", api_options.request
615615
)
616616
if is_general_error:
617-
return GeneralErrorResponse("general error from signout API")
617+
raise Exception("general error from signout API")
618618
return await original_signout_post(api_options, session, user_context)
619619

620620
original_implementation.signout_post = signout_post

0 commit comments

Comments
 (0)