Skip to content

Conversation

RandomProgramm3r
Copy link
Owner

refactor(user auth): Сonsolidate and enhance auth views, serializers, and validation

  • Refactor SignUpView & SignInView to use DRF generic views and SimpleJWT patterns
  • Simplify view logic: remove manual error handling, drop post overrides, and eliminate BaseCustomResponseMixin
  • Extract magic numbers/messages into top-level constants
  • Introduce OtherFieldSerializer for age and ISO 3166 validation
  • Update SignInSerializer:
    • @classmethod get_token with token_version claim
    • Atomic token_version increments via F() and update_fields
    • Bulk blacklist_other_tokens method
  • Simplify SignUpSerializer:
    • Use nested OtherFieldSerializer for other data
    • Properly handle Django ValidationError in create()
  • Cleanup: remove redundant imports"

- Refactored SignUpView and SignInView to better leverage DRF generic views and SimpleJWT patterns.
- Simplified view logic by removing manual error handling and post overrides where applicable, relying on serializers and base view implementations.
- Removed redundant imports.
- Removed BaseCustomResponseMixin.
- Extract “magic” numbers and messages into top-level constants for clarity
- Replace custom JSONField validator with nested `OtherFieldSerializer`
  that handles `age` and ISO 3166 country code validation
- Refactor `SignInSerializer`:
  - Use `F()` expressions and `update_fields` to atomically bump `token_version`
  - Extract token blacklisting into `blacklist_other_tokens` with bulk_create
  - Convert `get_token` to `@classmethod`, adding `token_version` claim
- Clean up `SignUpSerializer`:
  - Use nested `OtherFieldSerializer` for `other` JSON
  - Simplify `create()` logic and handle Django `ValidationError` correctly
- Removed redundant imports
@RandomProgramm3r RandomProgramm3r merged commit 2dd9ae0 into main Apr 30, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant