Tivix / django-rest-auth

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
www.tivix.com
MIT License
2.4k stars 663 forks source link

Django and react login with google #645

Open AREEG94FAHAD opened 3 years ago

AREEG94FAHAD commented 3 years ago

I am trying to use Django rest auth with react login with google.

backend In my views.py file

class GoogleLogin(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter

In urls.py

path('rest-auth/google/', GoogleLogin.as_view(), name='google_login')

I also configured the database with google credentials

Front part

In authapt.js

const googleLogin = async (accesstoken,code) => {
    const res = await axios.post(
      "http://localhost:8000/rest-auth/google/",
      {
        access_token: accesstoken,
        code

      }
    );
    console.log(res);
    return  res.status;
  };

In Logincomponent.jsx

<GoogleLogin
          clientId="clientId"
          buttonText="LOGIN WITH GOOGLE"
          onSuccess={googleLogin  }
          onFailure={googleLogin}
        /> 

but when I try to log in with my google account I got POST http://localhost:8000/rest-auth/google/ 400 (Bad Request) I want to save the user in the database of social account of backend any idea

mateokurti commented 2 years ago

I don't think this repo is taking any update. I suggest you to take a look at https://github.com/iMerica/dj-rest-auth

najiib49 commented 2 years ago

@AREEG94FAHAD I've implemented following the same steps and I'm getting same error where I can't save it to the database. Were you able to solve it?