diff --git a/auth.py b/auth.py index eeccfb8..cdc32dd 100644 --- a/auth.py +++ b/auth.py @@ -102,6 +102,9 @@ async def auth_twitch_callback(code: str, state: str, request: Request, db: Sess db.commit() + # Create a session for the user by storing their database ID. + request.session['user_id'] = user.id + # Redirect to a future dashboard page for a better user experience # This prepares us for Task 1.4 (Session Management) and Task 2.1 (Dashboard UI) return RedirectResponse(url="/dashboard") \ No newline at end of file diff --git a/main.py b/main.py index aed260b..2edfdba 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import os from fastapi import FastAPI from starlette.middleware.sessions import SessionMiddleware from starlette.staticfiles import StaticFiles -from starlette.responses import FileResponse +from starlette.responses import FileResponse, RedirectResponse import models from database import engine @@ -33,4 +33,18 @@ app.add_middleware(SessionMiddleware, secret_key=settings.ENCRYPTION_KEY) @app.get("/") async def read_root(): - return FileResponse(os.path.join(STATIC_DIR, "login.html")) \ No newline at end of file + return FileResponse(os.path.join(STATIC_DIR, "login.html")) + +@app.get("/dashboard") +async def read_dashboard(request: Request): + # This is our protected route. It checks if a user_id exists in the session. + if not request.session.get('user_id'): + # If not, redirect them to the login page. + return RedirectResponse(url="/") + return FileResponse(os.path.join(STATIC_DIR, "dashboard.html")) + +@app.get("/logout") +async def logout(request: Request): + # Clear the session cookie + request.session.clear() + return RedirectResponse(url="/") \ No newline at end of file diff --git a/static/dashboard.html b/static/dashboard.html new file mode 100644 index 0000000..bfc31df --- /dev/null +++ b/static/dashboard.html @@ -0,0 +1,20 @@ + + + + + + Dashboard - MultiChatOverlay + + + +
+

Dashboard

+

Welcome! You are successfully logged in.

+

Logout

+
+ + \ No newline at end of file