Updated to expose auth_app instead of app_route
This commit is contained in:
@@ -7,7 +7,7 @@ operations. Routes are organized in an APIRouter with /auth prefix.
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import Depends, HTTPException, status, FastAPI
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
|
||||
from ..core.auth import AuthService
|
||||
@@ -24,7 +24,7 @@ from ..models.user import UserCreate, UserResponse
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
||||
|
||||
|
||||
def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
def create_auth_app(auth_service: AuthService) -> FastAPI:
|
||||
"""
|
||||
Create and configure the authentication router.
|
||||
|
||||
@@ -40,13 +40,13 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
|
||||
Example:
|
||||
>>> from fastapi import FastAPI
|
||||
>>> from auth_module.api.routes import create_auth_router
|
||||
>>> from myauth.api.routes import create_auth_app
|
||||
>>>
|
||||
>>> app = FastAPI()
|
||||
>>> auth_router = create_auth_router(auth_service)
|
||||
>>> app.include_router(auth_router)
|
||||
>>> auth_api = create_auth_app(auth_service)
|
||||
>>> app.mount(auth_api)
|
||||
"""
|
||||
router = APIRouter(prefix="/auth", tags=["authentication"])
|
||||
auth_app = FastAPI(prefix="/auth", tags=["authentication"])
|
||||
|
||||
def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]) -> UserResponse:
|
||||
"""
|
||||
@@ -65,7 +65,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
HTTPException: 401 if token is invalid or expired.
|
||||
|
||||
Example:
|
||||
>>> @app.get("/protected")
|
||||
>>> @auth_app.get("/protected")
|
||||
>>> def protected_route(user: UserResponse = Depends(get_current_user)):
|
||||
>>> return {"user_id": user.id}
|
||||
"""
|
||||
@@ -86,7 +86,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/register",
|
||||
response_model=UserResponse,
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
@@ -128,7 +128,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/login",
|
||||
response_model=AccessTokenResponse,
|
||||
summary="Login with email and password",
|
||||
@@ -163,7 +163,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/logout",
|
||||
status_code=status.HTTP_204_NO_CONTENT,
|
||||
summary="Logout user",
|
||||
@@ -185,7 +185,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
auth_service.logout(request.refresh_token)
|
||||
return None
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/refresh",
|
||||
response_model=AccessTokenResponse,
|
||||
summary="Refresh access token",
|
||||
@@ -217,7 +217,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/password-reset-request",
|
||||
status_code=status.HTTP_200_OK,
|
||||
summary="Request password reset",
|
||||
@@ -252,7 +252,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/password-reset",
|
||||
status_code=status.HTTP_200_OK,
|
||||
summary="Reset password with token",
|
||||
@@ -284,7 +284,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.post(
|
||||
@auth_app.post(
|
||||
"/verify-email-request",
|
||||
status_code=status.HTTP_200_OK,
|
||||
summary="Request email verification",
|
||||
@@ -320,7 +320,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.get(
|
||||
@auth_app.get(
|
||||
"/verify-email",
|
||||
status_code=status.HTTP_200_OK,
|
||||
summary="Verify email with token",
|
||||
@@ -352,7 +352,7 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
detail=e.message
|
||||
)
|
||||
|
||||
@router.get(
|
||||
@auth_app.get(
|
||||
"/me",
|
||||
response_model=UserResponse,
|
||||
summary="Get current user",
|
||||
@@ -376,4 +376,4 @@ def create_auth_router(auth_service: AuthService) -> APIRouter:
|
||||
"""
|
||||
return current_user
|
||||
|
||||
return router
|
||||
return auth_app
|
||||
|
||||
Reference in New Issue
Block a user