Skip to content

Conversation

@codesungrape
Copy link
Collaborator

Description

This PR introduces JWT-based authentication to the API, starting with a /auth/register endpoint to allow new users to sign up with securely hashed passwords. This sets the foundation for a future /auth/login endpoint that will generate JWTs for authenticated access to protected routes.

Key Changes

  • Added /auth/register endpoint for creating new user accounts with Flask-PyMongo initialization in extensions.py.
  • Integrated password hashing using Flask-Bcrypt.
  • ONLY auth routes is currently using Flask Blueprint atm for better modularity- this is intentional for learning purposes.
  • Updated OpenAPI documentation for the new endpoint.
  • Added comprehensive validation and error handling for registration.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
  • Code refactor (improving code quality without changing functionality)

How Has This Been Tested?

Tests run with mocked MongoDB connection.
Verified responses match OpenAPI schema.
CI/CD
CURL
Added automated tests covering:

  • Successful registration
  • Missing or invalid fields
  • Empty/invalid JSON payloads

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My individual commit messages are descriptive and follow our commit guidelines
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Move app/routes.py to app/routes/legacy_routes.py and rename function to register_legacy_routes(). Add app/__init__.py to centralize route registration. Register Blueprint in __init__.py. Improves modularity and prepares for future structure.
Includes duplicate email check, password hashing using bcrypt, and database insertion. Previously written registration tests now pass.
Copy link

Copilot AI left a comment

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 introduces JWT-based authentication foundation by adding a new user registration endpoint and refactoring the application to use Flask-PyMongo. The changes prepare the system for future JWT authentication by establishing user management capabilities with secure password hashing.

  • Added /auth/register endpoint with comprehensive validation and error handling
  • Integrated Flask-PyMongo extension and Flask-Bcrypt for secure password hashing
  • Refactored route structure to separate authentication routes using Flask Blueprints

Reviewed Changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
app/init.py Initialize Flask-PyMongo extension and register authentication blueprint
app/extensions.py Create global PyMongo instance for shared database access
app/routes/auth_routes.py Implement user registration endpoint with validation and password hashing
app/routes/legacy_routes.py Rename route registration function for consistency
openapi.yml Add OpenAPI documentation for user registration endpoint
tests/test_auth.py Add comprehensive tests for registration endpoint scenarios
tests/conftest.py Add users collection setup fixture and mongomock configuration
Multiple test files Update import paths and function references after route refactoring

"password_hash": hashed_password.decode("utf-8"),
}
).inserted_id
print(user_id)
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The print statement should be removed from production code. Consider using proper logging instead if debugging information is needed.

Suggested change
print(user_id)
logging.info("Registered new user with id: %s", user_id)

Copilot uses AI. Check for mistakes.
codesungrape and others added 4 commits August 8, 2025 14:07
Fix spelling error

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fix spelling error 2

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fix spelling error 3

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fix spelling error 4

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codesungrape codesungrape merged commit 7df5893 into main Aug 8, 2025
2 checks passed
@codesungrape codesungrape deleted the feature/upgrade-to-JWT-route-protection branch August 11, 2025 08:18
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