dj-rest-auth verification email give me wrong url

39 views Asked by At

I implemented the email authentication function using dj rest auth, but it worked fine locally, but when I deployed it, the authentication email URL came out strangely. I registered my backend domain in admin's site>site.

this is my settings.py

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"  
EMAIL_PORT = "587"  
EMAIL_HOST_USER = "[email protected]"  
EMAIL_HOST_PASSWORD = "app_password"  
EMAIL_USE_TLS = True  
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER  
STATIC_URL = "/static/"

ACCOUNT_CONFIRM_EMAIL_ON_GET = True  
ACCOUNT_EMAIL_REQUIRED = True

ACCOUNT_EMAIL_VERIFICATION = "mandatory"


EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = (
    "/"  
)

ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1

ACCOUNT_EMAIL_SUBJECT_PREFIX = "WowYouToo"

and this is my accounts/views.py

class ConfirmEmailView(APIView):
    permission_classes = [AllowAny]

    def get(self, *args, **kwargs):
        
        self.object = confirmation = self.get_object()
        confirmation.confirm(self.request)
        return HttpResponseRedirect("accounts/")  

    def get_object(self, queryset=None):
        
        key = self.kwargs["key"]
        email_confirmation = EmailConfirmationHMAC.from_key(key)
        if not email_confirmation:
            if queryset is None:
                queryset = self.get_queryset()
            try:
                email_confirmation = queryset.get(key=key.lower())
            except EmailConfirmation.DoesNotExist:
                return HttpResponseRedirect("accounts/")  
        return email_confirmation

    def get_queryset(self):
        qs = EmailConfirmation.objects.all_valid()
        
        qs = qs.select_related("email_address__user")
        
        return qs


class CustomRegisterView(RegisterView):
    serializer_class = CustomRegisterSerializer
    permission_classes = [permissions.AllowAny]


class CustomTokenObtainPairView(TokenObtainPairView):
    
    serializer_class = CustomTokenObtainPairSerializer

the url in verification email is 'http://backend/accounts/confirm-email/Mzk:1r99pa:fG8rVgPl5q4WBQzs3saCYGKeVsquqwlvcFtwPvys3Wg/'

I tried to add URL_FRONT in settings.py and changed every HttpResponseRedirect urls...I also changed domain using shell but that 'http://backend/' never changed.

1

There are 1 answers

0
mariodev On

Make sure you have proper site app entries for prod environment. dj-rest-auth uses this to generate the absolute url in your emails (via django-allauth).

code ref: https://github.com/pennersr/django-allauth/blob/df41f2866a66b792a0e27611250cfd500fa956e2/allauth/utils.py#L252