Added: Dashboard html file and routing

This commit is contained in:
2025-11-17 01:50:06 +01:00
parent cafb39d9df
commit f2ebde841d
3 changed files with 39 additions and 2 deletions

View File

@@ -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")

18
main.py
View File

@@ -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"))
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="/")

20
static/dashboard.html Normal file
View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - MultiChatOverlay</title>
<style>
body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f2f5; margin: 0; }
.dashboard-container { text-align: center; padding: 40px; background-color: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
a { color: #9146FF; }
</style>
</head>
<body>
<div class="dashboard-container">
<h1>Dashboard</h1>
<p>Welcome! You are successfully logged in.</p>
<p><a href="/logout">Logout</a></p>
</div>
</body>
</html>