From 312d6ceb90d3b9fa4bbd866fd847d70c14f2d7a0 Mon Sep 17 00:00:00 2001 From: Alvaro Chevez Date: Wed, 18 Jan 2023 12:42:24 -0600 Subject: [PATCH] fix: ignore first and last name if display name comes null from firebase --- django_firebase_auth/firebase_auth.py | 19 ++++++++++++------- setup.py | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/django_firebase_auth/firebase_auth.py b/django_firebase_auth/firebase_auth.py index 991ef2d..23721c2 100644 --- a/django_firebase_auth/firebase_auth.py +++ b/django_firebase_auth/firebase_auth.py @@ -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") diff --git a/setup.py b/setup.py index 292856a..aad1455 100644 --- a/setup.py +++ b/setup.py @@ -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",