TheFastOrg / Backend

Apache License 2.0
0 stars 0 forks source link

Sweep(slow): Google Auth should return user token, name and email as a response for login #12

Closed mhd-medfa closed 1 year ago

mhd-medfa commented 1 year ago

You need to fix the Google authentication to return the user token, email and name as a response for login.

The current behaviour, at /accounts/login when user login with the Google account the user will be registered and all the data will show up in the Django admin panel, BUT the user will be redirected to /accounts/profile and no token will be returned in the response. We need the token as we will use this Google auth in our mobile apps to help our users to login and enter to their personal profiles.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/TheFastOrg/Backend/pull/14.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 0 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/TheFastOrg/Backend/blob/cb29c3e7401fc91f4c82df1c3cdd340c4e30b35b/backend/backend/settings.py#L1-L193 https://github.com/TheFastOrg/Backend/blob/cb29c3e7401fc91f4c82df1c3cdd340c4e30b35b/backend/ba7besh/migrations/0001_initial.py#L1-L145

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
backend/ba7besh/views.py Update the GoogleLoginView class to include the user token, email, and name in the response for login. Use the id_token returned by Google to generate the user token.
backend/ba7besh/serializers.py Modify the UserSerializer class to include the user token, email, and name fields in the response for login.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Fix Google Auth to return user token, name, and email in login response sweep/fix-google-auth

Description

This PR fixes the Google authentication in the backend to return the user token, name, and email as a response for login. Currently, the user is redirected to the profile page after login, but no token is returned in the response. This update is necessary to enable users to access their personal profiles in the mobile apps.

Summary of Changes

  • Modified the GoogleLoginView class in ba7besh/views.py to include the user token, email, and name in the response for login. The id_token returned by Google is used to generate the user token.
  • Updated the UserSerializer class in ba7besh/serializers.py to include the user token, email, and name fields in the response for login.

Please review and merge these changes to enable proper Google authentication and return the necessary user information in the login response.


Step 4: ⌨️ Coding

File Instructions Progress
backend/ba7besh/views.py Update the GoogleLoginView class to include the user token, email, and name in the response for login. Use the id_token returned by Google to generate the user token. ✅ Commit 0095e4d
backend/ba7besh/serializers.py Modify the UserSerializer class to include the user token, email, and name fields in the response for login. ✅ Commit 0095e4d I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are the my self-reviews of my changes at sweep/fix-google-auth.

Here is the 1st review

No changes required. The code changes in backend/ba7besh/views.py look good. A new class GoogleLoginView is added with a login method that handles the login process using an id_token. The code appears to be complete and there are no obvious errors or unimplemented sections. Well done!

I finished incorporating these changes.


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue. Join Our Discord