diff --git a/gotrue/_async/gotrue_client.py b/gotrue/_async/gotrue_client.py index a29785bc..f34361ab 100644 --- a/gotrue/_async/gotrue_client.py +++ b/gotrue/_async/gotrue_client.py @@ -30,6 +30,7 @@ model_dump, model_dump_json, model_validate, + parse_auth_otp_response, parse_auth_response, parse_sso_response, parse_user_response, @@ -46,6 +47,7 @@ AuthMFAListFactorsResponse, AuthMFAUnenrollResponse, AuthMFAVerifyResponse, + AuthOtpResponse, AuthResponse, CodeExchangeParams, DecodedJWTDict, @@ -365,7 +367,7 @@ async def unlink_identity(self, identity): async def sign_in_with_otp( self, credentials: SignInWithPasswordlessCredentials, - ) -> AuthResponse: + ) -> AuthOtpResponse: """ Log in a user using magiclink or a one-time password (OTP). @@ -399,7 +401,7 @@ async def sign_in_with_otp( }, }, redirect_to=email_redirect_to, - xform=parse_auth_response, + xform=parse_auth_otp_response, ) if phone: return await self._request( @@ -413,7 +415,7 @@ async def sign_in_with_otp( "captcha_token": captcha_token, }, }, - xform=parse_auth_response, + xform=parse_auth_otp_response, ) raise AuthInvalidCredentialsError( "You must provide either an email or phone number" diff --git a/gotrue/_sync/gotrue_client.py b/gotrue/_sync/gotrue_client.py index c495f857..7399d0f1 100644 --- a/gotrue/_sync/gotrue_client.py +++ b/gotrue/_sync/gotrue_client.py @@ -30,6 +30,7 @@ model_dump, model_dump_json, model_validate, + parse_auth_otp_response, parse_auth_response, parse_sso_response, parse_user_response, @@ -46,6 +47,7 @@ AuthMFAListFactorsResponse, AuthMFAUnenrollResponse, AuthMFAVerifyResponse, + AuthOtpResponse, AuthResponse, CodeExchangeParams, DecodedJWTDict, @@ -365,7 +367,7 @@ def unlink_identity(self, identity): def sign_in_with_otp( self, credentials: SignInWithPasswordlessCredentials, - ) -> AuthResponse: + ) -> AuthOtpResponse: """ Log in a user using magiclink or a one-time password (OTP). @@ -399,7 +401,7 @@ def sign_in_with_otp( }, }, redirect_to=email_redirect_to, - xform=parse_auth_response, + xform=parse_auth_otp_response, ) if phone: return self._request( @@ -413,7 +415,7 @@ def sign_in_with_otp( "captcha_token": captcha_token, }, }, - xform=parse_auth_response, + xform=parse_auth_otp_response, ) raise AuthInvalidCredentialsError( "You must provide either an email or phone number" diff --git a/gotrue/helpers.py b/gotrue/helpers.py index ba61a1af..0c9a0613 100644 --- a/gotrue/helpers.py +++ b/gotrue/helpers.py @@ -13,6 +13,7 @@ from .errors import AuthApiError, AuthError, AuthRetryableError, AuthUnknownError from .types import ( + AuthOtpResponse, AuthResponse, GenerateLinkProperties, GenerateLinkResponse, @@ -72,6 +73,10 @@ def parse_auth_response(data: Any) -> AuthResponse: return AuthResponse(session=session, user=user) +def parse_auth_otp_response(data: Any) -> AuthOtpResponse: + return model_validate(AuthOtpResponse, data) + + def parse_link_response(data: Any) -> GenerateLinkResponse: properties = GenerateLinkProperties( action_link=data.get("action_link"), diff --git a/gotrue/types.py b/gotrue/types.py index 609f1011..ee260b04 100644 --- a/gotrue/types.py +++ b/gotrue/types.py @@ -89,6 +89,12 @@ class AuthResponse(BaseModel): session: Union[Session, None] = None +class AuthOtpResponse(BaseModel): + user: None = None + session: None = None + message_id: Union[str, None] = None + + class OAuthResponse(BaseModel): provider: Provider url: str