Deal with absence of callback function

It may be None, so then we don't need to call back. The consumer may just take it from self._user_profile.

Contributes to issue CURA-8539.
This commit is contained in:
Ghostkeeper 2021-11-19 16:23:48 +01:00
parent a5202b61d2
commit acbbf83510
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -74,19 +74,22 @@ class AuthorizationService:
"""
if self._user_profile:
# We already obtained the profile. No need to make another request for it.
callback(self._user_profile)
if callback is not None:
callback(self._user_profile)
return
# If no user profile was stored locally, we try to get it from JWT.
def store_profile(profile: Optional["UserProfile"]):
if profile is not None:
self._user_profile = profile
callback(profile)
if callback is not None:
callback(profile)
elif self._auth_data:
# If there is no user profile from the JWT, we have to log in again.
Logger.warning("The user profile could not be loaded. The user must log in again!")
self.deleteAuthData()
callback(None)
if callback is not None:
callback(None)
self._parseJWT(callback = store_profile)