-
Notifications
You must be signed in to change notification settings - Fork 0
Implement JWT authentication with signup, login, and refresh endpoints #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b1a078e
Implement JWT authentication with signup, login, and token refresh en…
saudzahirr ddba710
Enhance JWT authentication and vendor management
saudzahirr 0cfc50a
Enhance code quality and documentation across the application
saudzahirr 12a1274
Refactor middleware request ID function and update JWT dependency ver…
saudzahirr 3a0c8b1
Enhance request ID validation in middleware and update integration te…
saudzahirr 10a7615
Refactor exception handling and response schemas for improved clarity…
saudzahirr e20c328
Refactor authentication routes by removing login endpoint; update ven…
saudzahirr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ htmlcov | |
| *.env | ||
| build/ | ||
| dist/ | ||
| *.log | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| from fastapi import APIRouter | ||
|
|
||
| from app.api.routes import health, login | ||
| from app.api.routes import auth, health | ||
|
|
||
|
|
||
| api_router = APIRouter() | ||
| api_router.include_router(health.router, tags=["health"]) | ||
| api_router.include_router(login.router, prefix="/login", tags=["login"]) | ||
| api_router.include_router(auth.router, prefix="/auth", tags=["auth"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """Auth routes — signup, login, token refresh.""" | ||
|
|
||
| from fastapi import APIRouter, status | ||
|
|
||
| from app.api.deps import CursorDep, SettingsDep | ||
| from app.schemas.auth import ( | ||
| LoginRequest, | ||
| RefreshRequest, | ||
| SignupRequest, | ||
| SignupResponse, | ||
| TokenPair, | ||
| ) | ||
| from app.schemas.response import SuccessResponse | ||
| from app.services import auth as auth_service | ||
|
|
||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.post( | ||
| "/signup", | ||
| status_code=status.HTTP_201_CREATED, | ||
| response_model=SuccessResponse[SignupResponse], | ||
| ) | ||
| def signup( | ||
| body: SignupRequest, cursor: CursorDep, settings: SettingsDep | ||
| ) -> SuccessResponse[SignupResponse]: | ||
| """Create a new vendor account. | ||
|
|
||
| Returns: | ||
| SuccessResponse[SignupResponse]: The created vendor. | ||
| """ | ||
| result = auth_service.signup( | ||
| cursor=cursor, | ||
| email=body.email, | ||
| password=body.password, | ||
| client_id=body.client_id, | ||
| settings=settings, | ||
| ) | ||
| return SuccessResponse(data=result) | ||
|
|
||
|
|
||
| @router.post("/login", response_model=SuccessResponse[TokenPair]) | ||
| def login( | ||
| body: LoginRequest, cursor: CursorDep, settings: SettingsDep | ||
| ) -> SuccessResponse[TokenPair]: | ||
| """Authenticate a vendor and return an access/refresh token pair. | ||
|
|
||
| Returns: | ||
| SuccessResponse[TokenPair]: The token pair. | ||
| """ | ||
| result = auth_service.login( | ||
| cursor=cursor, | ||
| email=body.email, | ||
| password=body.password, | ||
| client_id=body.client_id, | ||
| settings=settings, | ||
| ) | ||
| return SuccessResponse(data=result) | ||
|
|
||
|
|
||
| @router.post("/refresh", response_model=SuccessResponse[TokenPair]) | ||
| def refresh( | ||
| body: RefreshRequest, cursor: CursorDep, settings: SettingsDep | ||
| ) -> SuccessResponse[TokenPair]: | ||
| """Issue a new token pair using a valid refresh token. | ||
|
|
||
| Returns: | ||
| SuccessResponse[TokenPair]: The new token pair. | ||
| """ | ||
| result = auth_service.refresh( | ||
| refresh_token_str=body.refresh_token, | ||
| client_id=body.client_id, | ||
| cursor=cursor, | ||
| settings=settings, | ||
| ) | ||
| return SuccessResponse(data=result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from fastapi import APIRouter | ||
|
|
||
|
|
||
| router = APIRouter() | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.