I have implemented my API with djoser but when i try to access the route http://127.0.0.1:8000/auth/user/
to create a new user in postman i receive the error Forbidden (403) CSRF verification failed. Request aborted.
Here is a summary of my implementation.
SETTINGS file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
'djoser',
'accounts',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
AUTH_USER_MODEL = 'accounts.UserAccount'
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ['rest_framework.permissions.IsAuthenticated'],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
}
CORS_ALLOW_ALL_ORIGINS = True
DJOSER = {
'LOGIN_FIELD' : 'email',
'PASSWORD_RESET_CONFIRM_URL' : 'password-reset/{uid}/{token}',
'USERNAME_RESET_CONFIRM_URL' : 'username-reset/{uid}/{token}',
'SEND_ACTIVATION_EMAIL¶' : True,
'SEND_CONFIRMATION_EMAIL' : True,
'PASSWORD_CHANGED_EMAIL_CONFIRMATION' : True,
'USERNAME_CHANGED_EMAIL_CONFIRMATION' : True,
'ACTIVATION_URL' : 'activate/{uid}/{token}',
'USER_CREATE_PASSWORD_RETYPE' : True,
'SET_PASSWORD_RETYPE' : True,
'PASSWORD_RESET_CONFIRM_RETYPE' : True,
'USERNAME_RESET_CONFIRM_RETYPE' : True,
'LOGOUT_ON_PASSWORD_CHANGE' : True,
'SERIALIZERS' : {
'user_create' : 'accounts.serializers.UserCreateSerializer',
'user' : 'accounts.serializers.UserCreateSerializer',
'user_delete' : 'djoser.serializers.UserDeleteSerializer',
},
}
root urls.py
from django.urls import path, include, re_path
from django.views.generic import TemplateView
urlpatterns = [
# path('admin/', admin.site.urls),
path('auth/', include('djoser.urls')),
path('auth/', include('djoser.urls.jwt')),
]
urlpatterns += [
re_path(r'^.*', TemplateView.as_view(template_name='index.html'))
]
error on command prompt
Forbidden (CSRF cookie not set.): /auth/user/
[07/Sep/2023 13:51:15] "POST /auth/user/ HTTP/1.1" 403 2870
error on postman
Anyone with an idea what i might be doing wrong? thanks in advance