Skip to content

Commit 536ad2c

Browse files
authored
feat: add resend method (#587)
1 parent d54feeb commit 536ad2c

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

supabase_auth/_async/gotrue_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
OAuthResponse,
6262
Options,
6363
Provider,
64+
ResendCredentials,
6465
Session,
6566
SignInAnonymouslyCredentials,
6667
SignInWithIdTokenCredentials,
@@ -519,6 +520,41 @@ async def sign_in_with_otp(
519520
"You must provide either an email or phone number"
520521
)
521522

523+
async def resend(
524+
self,
525+
credentials: ResendCredentials,
526+
) -> AuthOtpResponse:
527+
"""
528+
Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
529+
"""
530+
email = credentials.get("email")
531+
phone = credentials.get("phone")
532+
type = credentials.get("type")
533+
options = credentials.get("options", {})
534+
email_redirect_to = options.get("email_redirect_to")
535+
captcha_token = options.get("captcha_token")
536+
body = {
537+
"type": type,
538+
"gotrue_meta_security": {
539+
"captcha_token": captcha_token,
540+
},
541+
}
542+
543+
if email is None and phone is None:
544+
raise AuthInvalidCredentialsError(
545+
"You must provide either an email or phone number"
546+
)
547+
548+
body.update({"email": email} if email else {"phone": phone})
549+
550+
return await self._request(
551+
"POST",
552+
"resend",
553+
body=body,
554+
redirect_to=email_redirect_to if email else None,
555+
xform=parse_auth_otp_response,
556+
)
557+
522558
async def verify_otp(self, params: VerifyOtpParams) -> AuthResponse:
523559
"""
524560
Log in a user given a User supplied OTP received via mobile.

supabase_auth/_sync/gotrue_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
OAuthResponse,
6262
Options,
6363
Provider,
64+
ResendCredentials,
6465
Session,
6566
SignInAnonymouslyCredentials,
6667
SignInWithIdTokenCredentials,
@@ -513,6 +514,41 @@ def sign_in_with_otp(
513514
"You must provide either an email or phone number"
514515
)
515516

517+
def resend(
518+
self,
519+
credentials: ResendCredentials,
520+
) -> AuthOtpResponse:
521+
"""
522+
Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
523+
"""
524+
email = credentials.get("email")
525+
phone = credentials.get("phone")
526+
type = credentials.get("type")
527+
options = credentials.get("options", {})
528+
email_redirect_to = options.get("email_redirect_to")
529+
captcha_token = options.get("captcha_token")
530+
body = {
531+
"type": type,
532+
"gotrue_meta_security": {
533+
"captcha_token": captcha_token,
534+
},
535+
}
536+
537+
if email is None and phone is None:
538+
raise AuthInvalidCredentialsError(
539+
"You must provide either an email or phone number"
540+
)
541+
542+
body.update({"email": email} if email else {"phone": phone})
543+
544+
return self._request(
545+
"POST",
546+
"resend",
547+
body=body,
548+
redirect_to=email_redirect_to if email else None,
549+
xform=parse_auth_otp_response,
550+
)
551+
516552
def verify_otp(self, params: VerifyOtpParams) -> AuthResponse:
517553
"""
518554
Log in a user given a User supplied OTP received via mobile.

supabase_auth/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,30 @@ class SignInWithPhoneAndPasswordlessCredentials(TypedDict):
376376
]
377377

378378

379+
class ResendEmailCredentialsOptions(TypedDict):
380+
email_redirect_to: NotRequired[str]
381+
captcha_token: NotRequired[str]
382+
383+
384+
class ResendEmailCredentials(TypedDict):
385+
type: Literal["signup", "email_change"]
386+
email: str
387+
options: NotRequired[ResendEmailCredentialsOptions]
388+
389+
390+
class ResendPhoneCredentialsOptions(TypedDict):
391+
captcha_token: NotRequired[str]
392+
393+
394+
class ResendPhoneCredentials(TypedDict):
395+
type: Literal["sms", "phone_change"]
396+
phone: str
397+
options: NotRequired[ResendPhoneCredentialsOptions]
398+
399+
400+
ResendCredentials = Union[ResendEmailCredentials, ResendPhoneCredentials]
401+
402+
379403
class SignInWithOAuthCredentialsOptions(TypedDict):
380404
redirect_to: NotRequired[str]
381405
scopes: NotRequired[str]

0 commit comments

Comments
 (0)