Skip to content

refactor: Split auth into services#54

Merged
PACHAKUTlQ merged 3 commits into
devfrom
refactor/auth-services
May 22, 2026
Merged

refactor: Split auth into services#54
PACHAKUTlQ merged 3 commits into
devfrom
refactor/auth-services

Conversation

@PACHAKUTlQ

Copy link
Copy Markdown
Collaborator

Split the auth workflow into services

@PACHAKUTlQ PACHAKUTlQ requested a review from A-lexisL May 22, 2026 15:02
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/flows.py Dismissed
Comment thread apps/auth/services/questionnaire.py Dismissed
Comment thread apps/auth/services/questionnaire.py Dismissed
@A-lexisL A-lexisL requested a review from Copilot May 22, 2026 15:18
@PACHAKUTlQ PACHAKUTlQ changed the title Refactor/auth services refactor: Split auth into services May 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the authentication workflow by extracting most of the business logic from apps/auth/views.py / apps/auth/utils.py into a dedicated apps/auth/services/ layer, aiming to make the auth flow more modular and easier to maintain.

Changes:

  • Moved OTP/temp-token, questionnaire callback verification, password validation, captcha verification, and user session creation into service modules.
  • Simplified DRF views to delegate to service functions and translate ServiceError into HTTP responses.
  • Reduced apps/auth/utils.py to only contain CSRF-enforcing session authentication.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/auth/views.py Delegates auth endpoints to services.* and centralizes error-to-Response mapping.
apps/auth/utils.py Removes previous auth helpers; keeps only CSRFCheckSessionAuthentication.
apps/auth/services/init.py Public re-exports for the new auth service surface.
apps/auth/services/types.py Adds shared dataclasses (ServiceError, AuthIntent, etc.).
apps/auth/services/flows.py Implements the main auth flows (initiate, verify callback, signup, reset, password login).
apps/auth/services/tokens.py Extracts Redis + token/OTP generation/storage helpers.
apps/auth/services/questionnaire.py Extracts questionnaire API integration and survey detail lookup.
apps/auth/services/captcha.py Extracts Turnstile verification into a service module.
apps/auth/services/passwords.py Extracts password strength scoring/validation.
apps/auth/services/users.py Extracts user/session creation + Student integration.
apps/auth/init.py Removes default_app_config entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/auth/views.py
Comment thread apps/auth/services/questionnaire.py Outdated
Comment on lines +55 to +59
"""Fetch the latest questionnaire answer for a given account from the WJ API(specific api for actions).
Returns a tuple of (filtered_data, error_response).
`filtered_data` contains: id, submitted_at, user.account, and otp.
`error_response` is a DRF Response object if an error occurs, otherwise None.
"""
Comment thread apps/auth/services/users.py Outdated
Comment on lines +20 to +24
"""Helper function includes session management, user creation and Student model integration.
Returns a tuple of (user, error_response).
`user` is the user object on success, otherwise None.
`error_response` is a DRF Response object if an error occurs, otherwise None.
"""
@PACHAKUTlQ PACHAKUTlQ merged commit 0c96519 into dev May 22, 2026
5 checks passed
@PACHAKUTlQ PACHAKUTlQ deleted the refactor/auth-services branch May 22, 2026 15:31
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.

3 participants