diff --git a/.env.example b/.env.example index f20d0a7..8707775 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,7 @@ DJANGO_SECRET_KEY= DJANGO_ALLOWED_HOSTS=localhost,0.0.0.0,127.0.0.1 # Public base URL of the web frontend (used for links in emails, redirects, etc.) -FRONTEND_URL=http://localhost:5173 +FRONTEND_URL=http://localhost:3000 # ============================================================================= # Database (PostgreSQL) @@ -25,10 +25,11 @@ DATABASE_URL=postgres://user:password@localhost:5432/dbname REDIS_URL=redis://localhost:6379/0 # ============================================================================= -# CORS +# CORS / CSRF # ============================================================================= # Comma-separated for multiple origins (e.g. http://localhost:5173,http://localhost:3000) -CORS_ALLOWED_ORIGINS=http://localhost:5173 +CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000 +CSRF_TRUSTED_ORIGINS=http://localhost:5173,http://localhost:3000 # ============================================================================= # Email (SMTP) diff --git a/apps/users/services.py b/apps/users/services.py index 5ebc9c2..692b9c6 100644 --- a/apps/users/services.py +++ b/apps/users/services.py @@ -44,6 +44,9 @@ def restore_user(self, user_id: int) -> None: @transaction.atomic def create_user(self, payload: UserCreateIn) -> User: + if User.objects.all_with_deleted().filter(email__iexact=payload.email).exists(): # pyright: ignore[reportAttributeAccessIssue] + raise HttpError(409, "User with this email already exists.") + user = User.objects.create_user( username=payload.email, email=payload.email, diff --git a/config/settings/base.py b/config/settings/base.py index dcee7ea..9427cdf 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -65,6 +65,8 @@ CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS") CORS_ALLOW_CREDENTIALS = True +CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS") + HEADLESS_ONLY = True HEADLESS_SERVE_SPECIFICATION = True