From 11254095ff8973b577291a2d3576bdbafd59435b Mon Sep 17 00:00:00 2001 From: ramforth Date: Mon, 17 Nov 2025 00:23:54 +0100 Subject: [PATCH] docs: Update task board and align development plan --- DEVELOPMENT_PLAN.md | 7 ++++--- auth.py | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/DEVELOPMENT_PLAN.md b/DEVELOPMENT_PLAN.md index fdf3c2a..fecc99b 100644 --- a/DEVELOPMENT_PLAN.md +++ b/DEVELOPMENT_PLAN.md @@ -9,9 +9,10 @@ The goal is to create a service where streamers can log in using their platform ## 2. Technology Stack * **Team Communications:** Discord and Nextcloud, primarily. This can change. There's a list of links in the [README.md](README.md) -* **Backend (API & Chat Listeners):** Python (for Twitch/YouTube chat listeners), Node.js (for WebSocket server and potentially other APIs), PHP (for user management and web serving). -* **Database:** MySQL -* **Frontend:** HTML, CSS, JavaScript +* **Backend:** Python 3.9+ (FastAPI) +* **Database:** SQLite (for initial development) with SQLAlchemy ORM +* **Frontend:** Vanilla HTML, CSS, and JavaScript +* **Chat Listeners:** `twitchio` (Twitch), `pytchat` (YouTube) ## 3. Implementation Roadmap diff --git a/auth.py b/auth.py index b245209..d258f8f 100644 --- a/auth.py +++ b/auth.py @@ -79,13 +79,27 @@ async def auth_twitch_callback(code: str, state: str, request: Request, db: Sess user_response = await client.get(users_url, headers=headers) user_data = user_response.json()["data"][0] - # TODO: Upsert user into our database - # For now, we'll just return the user data as a proof of concept. - # Encrypt the tokens for storage encrypted_tokens = security.encrypt_tokens(access_token, refresh_token) - # Here you would create or update the user in your database - # user = db.query(models.User).filter_by(platform_user_id=user_data['id']).first() ... etc. + # --- Database Upsert Logic --- + # Check if the user already exists in our database + user = db.query(models.User).filter(models.User.platform_user_id == user_data['id']).first() - return {"message": "Twitch login successful!", "user": user_data, "encrypted_tokens": encrypted_tokens} \ No newline at end of file + if user: + # If user exists, update their details + user.username = user_data['login'] + user.encrypted_tokens = encrypted_tokens + else: + # If user does not exist, create a new record + user = models.User( + platform_user_id=user_data['id'], + username=user_data['login'], + platform="twitch", + encrypted_tokens=encrypted_tokens + ) + db.add(user) + + db.commit() + + return {"message": f"Successfully authenticated as {user_data['display_name']}. User data has been saved."} \ No newline at end of file