' + data + '
' + data + '
From 56ec151b70e7e062700c09bbf212fa60e511043d Mon Sep 17 00:00:00 2001
From: Guillem Borrell {error.error}
")
+ user = token.get("userinfo")
+ if user:
+ request.session["user"] = dict(user)
+
+ return RedirectResponse(url="/app")
+
+
+@app.route("/logout")
+async def logout(request: Request):
+ request.session.pop("user", None)
+ return RedirectResponse(url="/")
+
+
+@app.route("/user")
+async def user(request: Request):
+ user = request.session.get("user")
+ return user
class HealthCheck(BaseModel):
@@ -44,7 +104,7 @@ app.include_router(sessions.router)
app.include_router(files.router)
app.include_router(analysis.router)
app.mount(
- "/",
+ "/app",
StaticFiles(directory=static_path, html=True),
name="static",
)
diff --git a/src/hellocomputer/routers/sessions.py b/src/hellocomputer/routers/sessions.py
index 9d68dd1..3fc99ae 100644
--- a/src/hellocomputer/routers/sessions.py
+++ b/src/hellocomputer/routers/sessions.py
@@ -1,10 +1,9 @@
-from typing import Annotated
from uuid import uuid4
-from fastapi import APIRouter, Depends
+from fastapi import APIRouter
+from starlette.requests import Request
from fastapi.responses import PlainTextResponse
-from ..security import oauth2_scheme
# Scheme for the Authorization header
@@ -12,7 +11,9 @@ router = APIRouter()
@router.get("/new_session")
-async def get_new_session(token: Annotated[str, Depends(oauth2_scheme)]) -> str:
+async def get_new_session(request: Request) -> str:
+ user = request.session.get("user")
+ print(user)
return str(uuid4())
diff --git a/src/hellocomputer/security.py b/src/hellocomputer/security.py
index 5fa38a6..e69de29 100644
--- a/src/hellocomputer/security.py
+++ b/src/hellocomputer/security.py
@@ -1,3 +0,0 @@
-from fastapi.security import OAuth2PasswordBearer
-
-oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
diff --git a/src/hellocomputer/static/index.html b/src/hellocomputer/static/index.html
index 7ddff25..68c33d8 100644
--- a/src/hellocomputer/static/index.html
+++ b/src/hellocomputer/static/index.html
@@ -8,6 +8,7 @@
+
@@ -21,9 +22,17 @@
Hello, computer!