Skip to content

Commit

Permalink
create client for otp functions
Browse files Browse the repository at this point in the history
Signed-off-by: Bariq <[email protected]>
  • Loading branch information
bariqhibat committed Oct 6, 2021
1 parent 83031ad commit 68f699b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion gotrue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,42 @@ def sign_in(
email: Optional[str] = None,
password: Optional[str] = None,
provider: Optional[str] = None,
phone: Optional[str] = None,
) -> Dict[str, Any]:
"""Log in an exisiting user, or login via a third-party provider."""
self._remove_session()
if email is not None and password is None:
data = self.api.send_magic_link_email(email)
elif email is not None and password is not None:
data = self._handle_email_sign_in(email, password)
elif phone is not None and password is None:
data = self.api.send_mobile_otp(phone)
elif provider is not None:
data = self._handle_provider_sign_in(provider)
else:
raise ValueError("Email or provider must be defined, both can't be None.")
raise ValueError("Email, provider, or phone must be defined, all can't be None.")
return data

def verify_otp(
self,
phone: str,
token: str,
options: Optional[Dict[str, Any]] = {},
) -> Dict[str, Any]:
"""Log in a user given a User supplied OTP received via mobile."""
self._remove_session()

if options is None:
options = {}

data = self.api.verify_mobile_otp(phone, token, options)

if "access_token" in data:
session = data

self._save_session(session)
self._notify_all_subscribers('SIGNED _IN')

return data

def user(self) -> Optional[Dict[str, Any]]:
Expand Down

0 comments on commit 68f699b

Please sign in to comment.