From 9140498c6ce51e5249b3451de63b57a5795eed09 Mon Sep 17 00:00:00 2001 From: code002lover Date: Thu, 4 Dec 2025 17:03:08 +0100 Subject: [PATCH] feat: Conditionally render 'Add Opinion' form based on user authentication status and add Rocket server port configuration. --- Rocket.toml | 5 ++ frontend/src/PersonDetails.tsx | 132 +++++++++++++++++++++------------ 2 files changed, 90 insertions(+), 47 deletions(-) create mode 100644 Rocket.toml diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..fc46157 --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,5 @@ +[default] +port = 8000 + +[release] +port = 24237 diff --git a/frontend/src/PersonDetails.tsx b/frontend/src/PersonDetails.tsx index 7fbad69..e022669 100644 --- a/frontend/src/PersonDetails.tsx +++ b/frontend/src/PersonDetails.tsx @@ -1,6 +1,13 @@ import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; -import { Person, AddOpinionRequest, Game, GameList } from "../items"; +import { + Person, + AddOpinionRequest, + Game, + GameList, + AuthStatusRequest, + AuthStatusResponse, +} from "../items"; import { apiFetch } from "./api"; export const PersonDetails = () => { @@ -9,6 +16,35 @@ export const PersonDetails = () => { const [games, setGames] = useState([]); const [gameTitle, setGameTitle] = useState(""); const [wouldPlay, setWouldPlay] = useState(false); + const [currentUser, setCurrentUser] = useState(""); + + useEffect(() => { + const token = localStorage.getItem("token"); + if (token) { + const req = AuthStatusRequest.create({ token }); + const buffer = AuthStatusRequest.encode(req).finish(); + + apiFetch("/auth/get_auth_status", { + method: "POST", + headers: { + "Content-Type": "application/octet-stream", + }, + body: buffer, + }) + .then((res) => res.arrayBuffer()) + .then((buffer) => { + try { + const response = AuthStatusResponse.decode(new Uint8Array(buffer)); + if (response.authenticated) { + setCurrentUser(response.username); + } + } catch (e) { + console.error("Failed to decode auth status:", e); + } + }) + .catch(console.error); + } + }, []); useEffect(() => { apiFetch("/api/games") @@ -99,63 +135,65 @@ export const PersonDetails = () => { -
-

Add Opinion

+ {currentUser === name && (
-
- - -
+

Add Opinion

- setWouldPlay(e.target.checked)} - id="wouldPlay" - /> -
+
- Would Play - + setWouldPlay(e.target.checked)} + id="wouldPlay" + /> + +
+
-
- + )} ); };