Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions backend/src/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from fastapi import Depends,FastAPI
from fastapi.security import OAuth2PasswordBearer
from jwt_auth.db import safe_query
from fastapi import FastAPI
from jwt_auth.auth_router import router as auth_router
from jwt_auth.jwt_auth import decode_access_token
from business_router import router as business_router
from fastapi.middleware.cors import CORSMiddleware

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")

app = FastAPI()
Expand All @@ -20,22 +19,12 @@
allow_headers=["*"], # Authorization, Content-Type
)

#mount auth endpoints (login, logout,register,refresh)
#mount routers
app.include_router(auth_router)
app.include_router(business_router)

@app.get("example/endpoint")

def example_endpoint(token: str = Depends(oauth2_scheme)):
"""
how endpoints should be defined.
access token is extracted from cookies using Depends.
access token is validated using auth package.
if token is invalid, exception will be raised.

"""

user_id = decode_access_token(token)

return f"some action based on {user_id}"


2 changes: 2 additions & 0 deletions backend/src/business_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from jwt_auth.db import safe_query

18 changes: 18 additions & 0 deletions backend/src/business_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from fastapi import Depends,FastAPI,APIRouter, HTTPException
from fastapi.security import OAuth2PasswordBearer
from jwt_auth.jwt_auth import decode_access_token
import business_logic

router = APIRouter()

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")

@router.get("/sample-endpoint")
def sample_endpoint(token:str = Depends(oauth2_scheme)):

user_id = decode_access_token(token)

#do something by calling functions in business_logic.py

pass