Skip to content

Commit

Permalink
feat: add my info api
Browse files Browse the repository at this point in the history
  • Loading branch information
yaongmeow committed Jun 11, 2024
1 parent c963495 commit 225a2cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions BE/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from fastapi import FastAPI
from urllib.request import Request
from fastapi import FastAPI, Request
from utils import jwt_decoder

from routes.auth import auth_router
from routes.green import green_router
Expand Down Expand Up @@ -31,4 +33,12 @@
app.include_router(auth_router, prefix="/auth")
app.include_router(green_router, prefix="/green")
app.include_router(history_router, prefix="/history")
app.include_router(statistics_router, prefix="/statistics")
app.include_router(statistics_router, prefix="/statistics")


@app.get("/my_info")
def my_info(request: Request):
auth_header = request.headers.get('Authorization')
access_token = auth_header.split(' ')[1]
message, user = jwt_decoder(access_token, os.environ.get('JWT_SECRET_KEY_ACCESS'))
return user
2 changes: 1 addition & 1 deletion BE/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from database import create_session
from utils import jwt_decoder

auth_api = [ '/footprint/compute', '/footprint/visualize', '/history', '/history/statistics', '/green' ]
auth_api = [ '/history', '/history/statistics', '/green', '/green/codes', '/my_info' ]

class authentication_check(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint):
Expand Down

0 comments on commit 225a2cb

Please sign in to comment.