I'm developing an authentication API for a mobile app using dj-rest-auth in Django. After a user registers an account, a verification email is sent to the user with an activation key. However, when I try to verify the email by sending a POST request to the verification endpoint, I receive a 404 Not Found error. I'm unsure where the issue lies.
# main project urls.py
urlpatterns = [
# Other URL patterns...
path('register/', include('dj_rest_auth.registration.urls')),
# ...
]
Settings
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
#ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = ''
#ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = ''
SITE_ID = 1
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myEmail'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
EMAIL_CONFIRMATION_EXPIRE_DAYS = 7
#EMAIL_HOST_USER = os.environ.get("EMAIL_USER")
#EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_PASSWORD")
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
]
}
SIMPLE_JWT = {
'USER_ID_FIELD': 'email',
'ACCESS_TOKEN_LIFETIME': datetime.timedelta(minutes=15),
'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=10),
'ROTATE_REFRESH_TOKENS': True,
}
LOGIN_URL = 'https://localhost:8000/login/'
REST_AUTH = {
'USER_DETAILS_SERIALIZER' : 'users.serializers.CustomUserDetailsSerializer',
'REGISTER_SERIALIZER': 'users.serializers.UserRegisterSerializer',
'USE_JWT': True,
'JWT_AUTH_COOKIE': 'my-app-auth',
'JWT_AUTH_REFRESH_COOKIE': 'my-refresh-token',
'JWT_AUTH_HTTPONLY':False,
}
AUTHENTICATION_BACKENDS = [
'allauth.account.auth_backends.AuthenticationBackend',
'django.contrib.auth.backends.ModelBackend',
]
Issue:
When I try to verify the email by sending a POST request to the /register/verify-email/ endpoint with the activation key, I'm receiving a 404 Not Found error with body
{ "detail": "Not found." }
I'd appreciate any guidance on what might be causing the 404 error during the email verification process. If you've encountered a similar issue or if you have suggestions on how to troubleshoot this, I'd be grateful for your insights.
404 Not found error means that the url you're looking for doesn't exist:
you're looking for /register/verify-email/, make sure it exists in your dj_rest_auth.registration.urls