Skip to content

Commit

Permalink
fix: error in client update
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Oct 19, 2021
1 parent 9870078 commit a653408
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 4 additions & 7 deletions gotrue/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ async def verify_otp(
self._notify_all_subscribers(event=AuthChangeEvent.SIGNED_IN)
return response

async def user(self) -> Optional[User]:
def user(self) -> Optional[User]:
"""Returns the user data, if there is a logged in user."""
return self.current_user

async def session(self) -> Optional[Session]:
def session(self) -> Optional[Session]:
"""Returns the session data, if there is an active session."""
return self.current_session

Expand Down Expand Up @@ -312,7 +312,8 @@ async def update(self, *, attributes: UserAttributes) -> User:
jwt=self.current_session.access_token,
attributes=attributes,
)
self.current_user = response
self.current_session.user = response
await self._save_session(session=self.current_session)
self._notify_all_subscribers(event=AuthChangeEvent.USER_UPDATED)
return response

Expand Down Expand Up @@ -596,10 +597,6 @@ def _notify_all_subscribers(self, *, event: AuthChangeEvent) -> None:

async def _save_session(self, *, session: Session) -> None:
"""Save session to client."""
if not session.user:
raise ValueError("User of session is None")
if not session.expires_in:
raise ValueError("Expires_in of session is None or empty")
self.current_session = session
self.current_user = session.user
if session.expires_at:
Expand Down
7 changes: 2 additions & 5 deletions gotrue/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def update(self, *, attributes: UserAttributes) -> User:
jwt=self.current_session.access_token,
attributes=attributes,
)
self.current_user = response
self.current_session.user = response
self._save_session(session=self.current_session)
self._notify_all_subscribers(event=AuthChangeEvent.USER_UPDATED)
return response

Expand Down Expand Up @@ -588,10 +589,6 @@ def _notify_all_subscribers(self, *, event: AuthChangeEvent) -> None:

def _save_session(self, *, session: Session) -> None:
"""Save session to client."""
if not session.user:
raise ValueError("User of session is None")
if not session.expires_in:
raise ValueError("Expires_in of session is None or empty")
self.current_session = session
self.current_user = session.user
if session.expires_at:
Expand Down

0 comments on commit a653408

Please sign in to comment.