iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.65k stars 306 forks source link

Email verification error: Reverse for 'account_confirm_email' not found. #115

Open adrenaline681 opened 4 years ago

adrenaline681 commented 4 years ago

I've been trying to make this work for many hours but I still haven't been able to get email verification working.

I want to be able to send an email to the user pointing to a page on the frontend (React) where they can click a "verify" button and this will send a POST request to the server to verify the email. This last part is working, I tested sending a POST request to: /api/v1/auth/register/verify-email/ with the verification key and the email was verified correctly.

I just need to be able to send that email that contains a link pointing to the Frontend verification url.

I also read the FAQ of the documentation where it says "You should override this view/url to handle it in your API client somehow and then, send post to /verify-email/ endpoint with proper key." but I'm confused about how to do this.

Currently when I create a new user I get this error: _django.urls.exceptions.NoReverseMatch: Reverse for 'account_confirm_email' with arguments '('Mzc:1k37tD:vMJNfdAhauMQNlajyLPwSYDkbBY',)' not found._

In my settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password'

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

SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True 
ACCOUNT_USERNAME_REQUIRED = True 
ACCOUNT_AUTHENTICATION_METHOD = 'email' 
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'  
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 7

In my main/urls.py:

from django.contrib import admin
from django.urls import path, re_path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path('^api/(?P<version>(v1))/', include('apps.users.urls')),
]

In my users/urls.py:

from django.urls import path, include, re_path

urlpatterns = [
    path('auth/', include('dj_rest_auth.urls')),  
    path('auth/register/', include('dj_rest_auth.registration.urls')), 
]
mohmyo commented 4 years ago

There is a note about this in the docs:

image