Skip to content

Commit

Permalink
fix: consume code
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Nov 21, 2024
1 parent 6927117 commit e9d0f96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 14 additions & 1 deletion supertokens_python/recipe/passwordless/api/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
APIInterface,
APIOptions,
CheckCodeOkResult,
CheckCodeIncorrectUserInputCodeError,
CheckCodeExpiredUserInputCodeError,
CheckCodeRestartFlowError,
ConsumeCodeExpiredUserInputCodeError,
ConsumeCodeIncorrectUserInputCodeError,
ConsumeCodeOkResult,
Expand Down Expand Up @@ -545,6 +548,15 @@ async def consume_code_post(
phone_number=device_info.phone_number, email=device_info.email
)

check_credentials_response: Optional[
Union[
CheckCodeOkResult,
CheckCodeIncorrectUserInputCodeError,
CheckCodeExpiredUserInputCodeError,
CheckCodeRestartFlowError,
]
] = None

async def check_credentials(_: str):
nonlocal check_credentials_response
if check_credentials_response is None:
Expand Down Expand Up @@ -666,7 +678,8 @@ async def check_credentials(_: str):
return SignInUpPostNotAllowedResponse(reason=reason)

if check_credentials_response is not None:
return check_credentials_response
if not isinstance(check_credentials_response, CheckCodeOkResult):
return check_credentials_response

response = await api_options.recipe_implementation.consume_code(
pre_auth_session_id=pre_auth_session_id,
Expand Down
9 changes: 6 additions & 3 deletions supertokens_python/recipe/passwordless/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ def from_json(json: Dict[str, Any]) -> ConsumedDevice:
)

def to_json(self) -> Dict[str, Any]:
return {
result: Dict[str, Any] = {
"preAuthSessionId": self.pre_auth_session_id,
"failedCodeInputAttemptCount": self.failed_code_input_attempt_count,
"email": self.email,
"phoneNumber": self.phone_number,
}
if self.email is not None:
result["email"] = self.email
if self.phone_number is not None:
result["phoneNumber"] = self.phone_number
return result


class ConsumeCodeOkResult:
Expand Down

0 comments on commit e9d0f96

Please sign in to comment.