Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions gotrue/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
cookie_options : CookieOptions
The options for the cookie.
"""
if url.startswith("http"):
if url.startswith("http://"):
print(
"Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOTRUE EVER!\n"
"GoTrue REQUIRES HTTPS to work securely."
Expand All @@ -71,7 +71,7 @@ def __init__(
"headers": {**empty_or_default_headers, **headers},
"cookie_options": cookie_options,
}
self.api = api if api else SyncGoTrueAPI(**args)
self.api = api or SyncGoTrueAPI(**args)

def __enter__(self) -> SyncGoTrueClient:
return self
Expand Down Expand Up @@ -206,15 +206,15 @@ def sign_in(
self._remove_session()
if email and not password:
response = self.api.send_magic_link_email(email=email)
elif email and password:
elif email:
response = self._handle_email_sign_in(
email=email,
password=password,
redirect_to=redirect_to,
)
elif phone and not password:
response = self.api.send_mobile_otp(phone=phone)
elif phone and password:
elif phone:
response = self._handle_phone_sign_in(phone=phone, password=password)
elif refresh_token:
# current_session and current_user will be updated to latest
Expand Down Expand Up @@ -290,8 +290,7 @@ def refresh_session(self) -> Session:
"""
if not self.current_session:
raise ValueError("Not logged in.")
response = self._call_refresh_token()
return response
return self._call_refresh_token()

def update(self, *, attributes: UserAttributes) -> User:
"""Updates user data, if there is a logged in user.
Expand Down Expand Up @@ -523,12 +522,11 @@ def _handle_provider_sign_in(
scopes: Optional[str],
) -> str:
"""Sign in with provider."""
response = self.api.get_url_for_provider(
return self.api.get_url_for_provider(
provider=provider,
redirect_to=redirect_to,
scopes=scopes,
)
return response

def _recover_common(self) -> Optional[Tuple[Session, int, int]]:
"""Recover common logic"""
Expand Down Expand Up @@ -565,15 +563,16 @@ def _recover_and_refresh(self) -> None:
if not result:
return
session, expires_at, time_now = result
if expires_at < time_now:
if self.auto_refresh_token and session.refresh_token:
try:
self._call_refresh_token(refresh_token=session.refresh_token)
except APIError:
self._remove_session()
else:
if (
expires_at < time_now
and self.auto_refresh_token
and session.refresh_token
):
try:
self._call_refresh_token(refresh_token=session.refresh_token)
except APIError:
self._remove_session()
elif not session or not session.user:
elif expires_at < time_now or not session or not session.user:
self._remove_session()
else:
self._save_session(session=session)
Expand Down