Django Google Login : Üçüncü Taraf Giriş Hatası

Merhabalar django projeme google login ekledim ama şöyle bir sorunum var şu an normal şartlarda doğru bir şekilde giriş yapabiliyor ama google ile giriş yapıp tarayıcıda geriye gelip o google login kısmına geri gelip yeniden tiklarsam başlıktata ve görüntüdede göreceğiniz sayfayı alıyorum asıl sorum bu değil aslında ben bunu özelleştirmek veya tamamen hiç çıkmamasını sağlamak istiyorum bunu nasıl yapabilirim?

settings.py:

"""
Django settings for blog project.

Generated by 'django-admin startproject' using Django 5.1.1.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_6klj(tw(t81u5-oilw5=&8txf1z!%+4colk1o!dp0*t&jflku'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

SITE_ID = 2

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'article',
    'crispy_forms',
    "crispy_bootstrap5",
    "ckeditor",
    'django_cleanup.apps.CleanupConfig',
    "user",
    "django.contrib.sites",
    'allauth',  # Burada olmalı
    'allauth.account',  # Burada olmalı
    'allauth.socialaccount',  # Burada olmalı
    "allauth.socialaccount.providers.google",
]

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        },
    }
}



MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'allauth.account.middleware.AccountMiddleware',
]

ROOT_URLCONF = 'blog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,"templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

WSGI_APPLICATION = 'blog.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'tr'

TIME_ZONE = 'Europe/Istanbul'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR,"staticfiles")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR,"static"),
]

# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK = 'bootstrap5'

CKEDITOR_CONFIGS = {
    "default": {
        "removePlugins": "stylesheetparser",
        "allowedContent" : True,
    }
}

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR,"media")


AUTHENTICATION_BACKENDS = (
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend",

)

LOGIN_REDIRECT_URL = '/'  
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'  
LOGOUT_REDIRECT_URL = '/'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '<722444511487-2i7e9u3urlugcp2cp6slp09jjg7kgdg3.apps.googleusercontent.com>'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '<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>'
SOCIALACCOUNT_LOGIN_ON_GET=True

ACCOUNT_EMAIL_VERIFICATION = 'none'  

Sorunun anlaşılması için video çekin.

buraya video bırakamıyorum sanırım videonun streamable linki : Watch 2024-12-13 22-38-36 (online-video-cutter.com) | Streamable

Muhtemelen hata durumunda yönlendirme yok sadece hatayı gösterme var.

Boş bir projede auth testim:

Dolu bir projede auth testim:

All auth demo projesinde test edersen yine aynı şekilde hata gösterimi yapılıyor.
https://django.demo.allauth.org/accounts/google/login/?process=login

Dökümantasyonunda hata durumunda yönlendirme nasıl yapılır gibi bir açıklama göremedim tabi chatgptye göre bu yöntem işe yarar diyor ama yönlendirmeyi sağlayamadım sadece olay gerçekleşince error mesajını bastırabiliyorsun.

adapters.py

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from django.shortcuts import redirect
from django.contrib import messages

class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
    def on_authentication_error(self, request, provider_id, error=None, exception=None, *args, **kwargs):
        # Başarısız giriş durumunda mesaj ekleyin veya yönlendirme yapın
        messages.error(request, f"Login failed via {provider_id}. Please try again.")
        return redirect('home') # Başarısız giriş için yönlendirme yapılacak URL

settings.py

SOCIALACCOUNT_ADAPTER = 'a_users.adapters.CustomSocialAccountAdapter'

tamam yönlendirme olmasın nasıl o demo sitedeki gibi özelleştirebiliriz?

Tavsiyem puzzle birleştirmek yerine udemy yada youtube gözünüze kestirdiğiniz bir eğitimi bitirin.

Örnek:
Django + HTMX bir arada güzel bir eğitim.

udemy’de mustafa murat coşkun hocamızın python kursunu django kısmına kadar bitirdim dolayısıyla django temelim var ekstra bir kursa ihtiyacım varmı emin değilim. Ayrıca ingilizcemde videoları anlayacak kadar iyi değil en baştaki soruma internette yanıt aradım ama bulamadım o yüzden buraya sordum belki haklısınızdır detaylı bir kursu bitirmem gerekiyordur ama bence zaten türkçe çekilmiş en iyi python kurslarından birini sindire sindire neredeyse bitirmiş durumdayım ve dediğim gibi ingilizce içerik tüketme gibi bir imkanım şu anlık yok bu yüzden ekstra bir eğitimi tekrar izlemeye gerek duymuyorum.Bu arada ana sorumu daha çok araştırdım ama gerçekten nasıl yapacağımı bulamadım yardım edebilirseniz mutlu olurum.

Muhtemelen all-auth html template özelleştirmesini doğru yapamadınız yada hiç yapmadınız. Nerede hata yaptıgınızı birinin anlaması için tüm projenize bakması gerekli bunuda kimse yapmaz ondan sıfırdan bir projede bunu gösteren bir eğitim olsun diye örnek eğitimi gönderdim. Birde ingilizceden korkmayın anlamaya çalışın yazılımcının en büyük özelliği problem çözmektir. Başarılar dilerim

Dediklerinizi dikkate alacağım teşekkürler :slight_smile: