Django Rest框架&Vue.js;通过谷歌账号登录;“用户已使用此电子邮件地址注册。”

2024-09-28 22:04:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些通过谷歌帐号登录我的网站的问题。我通过Google创建了Registraion(使用vue Google登录,然后将数据发送到我的后端dj rest auth/Google/),这很好。但是,如果我试图登录用户,我会从后端服务器得到一个响应“用户已使用此电子邮件地址注册”。我该怎么做才能让用户通过Google帐户登录到我的web应用程序?如何登录用户但不注册

如果有人给我答案,我会很感激,因为我在调试和搜索答案上浪费了太多时间。我会把我的代码放在下面。如果你需要更多信息,请告诉我

谢谢大家!

# authenticate.views
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from dj_rest_auth.registration.views import SocialLoginView

class GoogleLogin(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter

#authenticate.urls
from django.urls import path
from . import views
urlpatterns = [
    path('google/', views.GoogleLogin.as_view(), name='google_login')
]
#backend_main.urls
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from authentication.views import GoogleLogin

from backend_main.api_views import get_router_urls

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hr-api/', include(get_router_urls())),
    path('demo-hr-api/', include('backend_main.urls')),
    path('accounts/', include('allauth.urls'), name='socialaccount_signup'),
    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
    path('dj-rest-auth/google/', GoogleLogin.as_view(), name='google_login'),
]

enter image description here

enter image description here


Tags: pathdjango用户fromimportauthrestinclude