Skip to content

Commit

Permalink
Merge pull request #4 from ProfileStash/main
Browse files Browse the repository at this point in the history
Changed approach on setting names to the User model
  • Loading branch information
maycuatroi authored Jan 18, 2023
2 parents eca2d48 + b243a06 commit cff701f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions django_firebase_auth/firebase_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,20 @@ def authenticate(self, request):
return None

striped_user_name = decoded_token["email"].split("@")[0]
display_name = decoded_token.get("name", striped_user_name)
first_name, last_name = self.convert_user_display_name(display_name)
defaults = {
"username": striped_user_name
}
# There are some instances where the display_name may come as null from firebase
display_name = decoded_token.get("name")
# If we have display_name, let's try and figure the first name and last name
if display_name:
first_name, last_name = self.convert_user_display_name(display_name)
defaults["first_name"] = first_name
if last_name:
defaults["last_name"] = last_name
user: User = User.objects.get_or_create(
email=decoded_token.get("email"),
defaults={
"username": striped_user_name,
"first_name": first_name,
"last_name": last_name,
},
defaults=defaults,
)[0]
profile: UserFirebaseProfile = UserFirebaseProfile.objects.get_or_create(
user=user, uid=decoded_token.get("uid")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="django-firebase-auth",
version="1.0.7",
version="1.0.8",
packages=find_packages(),
install_requires=["firebase-admin", "djangorestframework"],
url="https://github.com/maycuatroi/django-firebase-auth",
Expand Down

0 comments on commit cff701f

Please sign in to comment.