0

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.

  • Can you show us the contents of `dj_rest_auth.registration.urls`? – John Gordon Aug 26 '23 at 23:14
  • it can be found here. [dj_rest_auth.registration.urls](https://github.com/iMerica/dj-rest-auth/blob/master/dj_rest_auth/registration/urls.py) – Karim Ahmed Aug 27 '23 at 01:22
  • Try setting `DEBUG = True` in settings.py. This should give you an informative error page for the 404 error, explaining exactly what urls it tried and why it didn't match. – John Gordon Aug 27 '23 at 02:19
  • Actually, The endpoint exists, and the response is {"detail": "Not found.} Status Code 404 I think the problem mabey with the token – Karim Ahmed Aug 28 '23 at 15:52

1 Answers1

0

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

JimmyFl0
  • 96
  • 1
  • 8
  • Actually, The endpoint exists and the response is `{"detail": "Not found.} Status Code 404` I think the problem mabey with the token – Karim Ahmed Aug 27 '23 at 01:18