From f286e8b571be6731ad7fff876378829bd485c207 Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Tue, 5 Mar 2024 17:43:10 +0530 Subject: [PATCH] username integrity error solved --- accounts/api/views.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/accounts/api/views.py b/accounts/api/views.py index bda2198..809d76a 100644 --- a/accounts/api/views.py +++ b/accounts/api/views.py @@ -666,7 +666,18 @@ class GoogleLoginAPIView(APIView): ) principal_info = self.get_google_user_data(access_token) - ("principal_info: ", principal_info) + print("principal_info: ", principal_info) + + # Check if there was an error in fetching user data + if "error" in principal_info: + error_message = principal_info.get("error", {}).get( + "error_description", "An error occurred while fetching user data." + ) + return Response( + {"error": error_message}, + status=principal_info.get("status", status.HTTP_400_BAD_REQUEST), + ) + if not principal_info: return Response( {"error": "Failed to fetch user details or invalid access token"}, @@ -679,7 +690,7 @@ class GoogleLoginAPIView(APIView): {"error": "Email is required but not provided."}, status=status.HTTP_400_BAD_REQUEST, ) - ("email: ", email) + print("email: ", email) serializer = EmailSerializer( data={"email": email, "principal_type": principal_type} ) @@ -698,6 +709,7 @@ class GoogleLoginAPIView(APIView): principal, created = IAmPrincipal.objects.update_or_create( email=email, + username=email, defaults=defaults, ) principal_type_instance = IAmPrincipalType.objects.get(name=principal_type)