From db417e50d95b80b3f4e87ea7eeaff7817ff58337 Mon Sep 17 00:00:00 2001 From: code002lover Date: Sun, 11 Jan 2026 18:41:56 +0100 Subject: [PATCH] add edit/delete game capabilities --- admins.json | 1 + backend/src/auth.rs | 68 +++++- backend/src/lib.rs | 1 + backend/src/main.rs | 60 ++++++ backend/src/store.rs | 16 ++ frontend/items.ts | 19 +- frontend/src/App.tsx | 15 +- frontend/src/EditGame.tsx | 403 +++++++++++++++++++++++++++++++++++ frontend/src/GameDetails.tsx | 73 ++++++- frontend/src/api.ts | 6 + protobuf/items.proto | 1 + 11 files changed, 655 insertions(+), 8 deletions(-) create mode 100644 admins.json create mode 100644 frontend/src/EditGame.tsx diff --git a/admins.json b/admins.json new file mode 100644 index 0000000..3c0ce8e --- /dev/null +++ b/admins.json @@ -0,0 +1 @@ +["Code002Lover","HoherGeist"] diff --git a/backend/src/auth.rs b/backend/src/auth.rs index 19d3b14..9d69ff4 100644 --- a/backend/src/auth.rs +++ b/backend/src/auth.rs @@ -2,7 +2,7 @@ use crate::items; use crate::proto_utils::Proto; use rocket::State; use rocket::futures::lock::Mutex; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use uuid::Uuid; pub struct AuthState { @@ -24,6 +24,24 @@ impl Default for AuthState { } } +pub struct AdminState { + pub admins: Mutex>, +} + +impl AdminState { + pub fn new() -> Self { + Self { + admins: Mutex::new(crate::store::load_admins()), + } + } +} + +impl Default for AdminState { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug)] #[allow(dead_code)] pub struct Token { @@ -62,6 +80,48 @@ impl<'r> rocket::request::FromRequest<'r> for Token { } } +#[derive(Debug)] +pub struct AdminToken { + pub token: String, + pub username: String, +} + +#[rocket::async_trait] +impl<'r> rocket::request::FromRequest<'r> for AdminToken { + type Error = (); + + async fn from_request( + request: &'r rocket::Request<'_>, + ) -> rocket::request::Outcome { + let token = request.headers().get_one("Authorization"); + + match token { + Some(token) => { + if let Some(token) = token.strip_prefix("Bearer ") { + let auth_state = request.guard::<&State>().await.unwrap(); + let tokens = auth_state.tokens.lock().await; + + if let Some(username) = tokens.get(token) { + let admin_state = + request.guard::<&State>().await.unwrap(); + let admins = admin_state.admins.lock().await; + + if crate::store::is_admin(username, &admins) { + return rocket::request::Outcome::Success(AdminToken { + token: token.to_string(), + username: username.clone(), + }); + } + } + } + + rocket::request::Outcome::Error((rocket::http::Status::Forbidden, ())) + } + None => rocket::request::Outcome::Error((rocket::http::Status::Unauthorized, ())), + } + } +} + #[post("/login", data = "")] pub async fn login( state: &State, @@ -118,22 +178,28 @@ pub async fn logout( #[post("/get_auth_status", data = "")] pub async fn get_auth_status( state: &State, + admin_state: &State, request: Proto, ) -> items::AuthStatusResponse { let req = request.into_inner(); let tokens = state.tokens.lock().await; if let Some(username) = tokens.get(&req.token) { + let admins = admin_state.admins.lock().await; + let is_admin = crate::store::is_admin(username, &admins); + items::AuthStatusResponse { authenticated: true, username: username.clone(), message: "Authenticated".to_string(), + is_admin, } } else { items::AuthStatusResponse { authenticated: false, username: "".to_string(), message: "Not authenticated".to_string(), + is_admin: false, } } } diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 08c2ef6..6b365b1 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -9,4 +9,5 @@ pub mod auth; pub mod proto_utils; pub mod store; +pub use auth::AdminState; pub use store::User; diff --git a/backend/src/main.rs b/backend/src/main.rs index c06d8ad..7b63aaf 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -103,6 +103,63 @@ async fn add_game( Some(game) } +#[patch("/game", data = "")] +async fn update_game( + _token: auth::AdminToken, + game_list: &rocket::State>>, + user_list: &rocket::State>>, + game: proto_utils::Proto, +) -> Option { + let mut games = game_list.lock().await; + let mut game = game.into_inner(); + + game.title = game.title.trim().to_string(); + + if game.remote_id == 0 { + return None; + } + + let mut r_existing = None; + + if let Some(existing) = games.iter_mut().find(|g| g.title == game.title) { + existing.source = game.source; + existing.min_players = game.min_players; + existing.max_players = game.max_players; + existing.price = game.price; + existing.remote_id = game.remote_id; + + r_existing = Some(existing.clone()); + } + let users = user_list.lock().await; + save_state(&games, &users); + + r_existing +} + +#[delete("/game/")] +async fn delete_game( + _token: auth::AdminToken, + game_list: &rocket::State<Mutex<Vec<Game>>>, + user_list: &rocket::State<Mutex<Vec<User>>>, + title: &str, +) -> Option<items::Game> { + let mut games = game_list.lock().await; + + if let Some(pos) = games + .iter() + .position(|g| g.title.to_lowercase() == title.to_lowercase()) + { + let game = games.remove(pos); + + let users = user_list.lock().await; + save_state(&games, &users); + + return Some(game); + } + + None +} + #[post("/opinion", data = "<req>")] async fn add_opinion( token: auth::Token, @@ -334,6 +391,7 @@ async fn main() -> Result<(), std::io::Error> { rocket::build() .manage(Mutex::new(user_list)) .manage(auth::AuthState::new()) + .manage(auth::AdminState::new()) .manage(Mutex::new(game_list)) .mount( "/api", @@ -345,6 +403,8 @@ async fn main() -> Result<(), std::io::Error> { add_opinion, remove_opinion, add_game, + update_game, + delete_game, get_game_thumbnail, get_games_batch ], diff --git a/backend/src/store.rs b/backend/src/store.rs index 90098a4..d15f2b2 100644 --- a/backend/src/store.rs +++ b/backend/src/store.rs @@ -1,5 +1,6 @@ use crate::items::{Game, Person}; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; use std::fs::File; use std::io::BufReader; @@ -30,6 +31,7 @@ pub struct PersistentState { } pub const STATE_FILE: &str = "state.json"; +pub const ADMINS_FILE: &str = "admins.json"; pub fn save_state(games: &[Game], users: &[User]) { let mut games = games.to_vec(); @@ -57,3 +59,17 @@ pub fn load_state() -> Option<(Vec<Game>, Vec<User>)> { } None } + +pub fn load_admins() -> HashSet<String> { + if let Ok(file) = File::open(ADMINS_FILE) { + let reader = BufReader::new(file); + if let Ok(admins) = serde_json::from_reader::<_, Vec<String>>(reader) { + return admins.into_iter().map(|s| s.to_lowercase()).collect(); + } + } + HashSet::new() +} + +pub fn is_admin(username: &str, admins: &HashSet<String>) -> bool { + admins.contains(&username.to_lowercase()) +} diff --git a/frontend/items.ts b/frontend/items.ts index bffc235..414cbc7 100644 --- a/frontend/items.ts +++ b/frontend/items.ts @@ -98,6 +98,7 @@ export interface AuthStatusResponse { authenticated: boolean; username: string; message: string; + isAdmin: boolean; } export interface GameRequest { @@ -895,7 +896,7 @@ export const AuthStatusRequest: MessageFns<AuthStatusRequest> = { }; function createBaseAuthStatusResponse(): AuthStatusResponse { - return { authenticated: false, username: "", message: "" }; + return { authenticated: false, username: "", message: "", isAdmin: false }; } export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { @@ -909,6 +910,9 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { if (message.message !== "") { writer.uint32(26).string(message.message); } + if (message.isAdmin !== false) { + writer.uint32(32).bool(message.isAdmin); + } return writer; }, @@ -943,6 +947,14 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { message.message = reader.string(); continue; } + case 4: { + if (tag !== 32) { + break; + } + + message.isAdmin = reader.bool(); + continue; + } } if ((tag & 7) === 4 || tag === 0) { break; @@ -957,6 +969,7 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { authenticated: isSet(object.authenticated) ? globalThis.Boolean(object.authenticated) : false, username: isSet(object.username) ? globalThis.String(object.username) : "", message: isSet(object.message) ? globalThis.String(object.message) : "", + isAdmin: isSet(object.isAdmin) ? globalThis.Boolean(object.isAdmin) : false, }; }, @@ -971,6 +984,9 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { if (message.message !== "") { obj.message = message.message; } + if (message.isAdmin !== false) { + obj.isAdmin = message.isAdmin; + } return obj; }, @@ -982,6 +998,7 @@ export const AuthStatusResponse: MessageFns<AuthStatusResponse> = { message.authenticated = object.authenticated ?? false; message.username = object.username ?? ""; message.message = object.message ?? ""; + message.isAdmin = object.isAdmin ?? false; return message; }, }; diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7647d23..24a46fa 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,6 +6,7 @@ import { PersonDetails } from "./PersonDetails"; import { GameList } from "./GameList"; import { GameFilter } from "./GameFilter"; import { GameDetails } from "./GameDetails"; +import { EditGame } from "./EditGame"; import { ShaderBackground } from "./ShaderBackground"; import { BrowserRouter, Routes, Route, NavLink } from "react-router-dom"; import "./App.css"; @@ -88,7 +89,9 @@ function App() { }; useEffect(() => { - fetchPeople(); + if (token) { + fetchPeople(); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [token]); @@ -102,6 +105,7 @@ function App() { setToken(""); setPeople([]); localStorage.removeItem("token"); + localStorage.removeItem("isAdmin"); addToast("Logged out successfully", "info"); }; @@ -172,7 +176,14 @@ function App() { <Route path="/games" element={<GameList onShowToast={addToast} />} /> <Route path="/filter" element={<GameFilter />} /> <Route path="/person/:name" element={<PersonDetails />} /> - <Route path="/game/:title" element={<GameDetails />} /> + <Route + path="/game/:title" + element={<GameDetails onShowToast={addToast} />} + /> + <Route + path="/game/:title/edit" + element={<EditGame onShowToast={addToast} />} + /> </Routes> </div> </BrowserRouter> diff --git a/frontend/src/EditGame.tsx b/frontend/src/EditGame.tsx new file mode 100644 index 0000000..59d56a2 --- /dev/null +++ b/frontend/src/EditGame.tsx @@ -0,0 +1,403 @@ +import { useState, useEffect } from "react"; +import { useNavigate, useParams } from "react-router-dom"; +import { Game, Source } from "../items"; +import { apiFetch } from "./api"; +import type { ToastType } from "./Toast"; + +interface Props { + onShowToast?: (message: string, type?: ToastType) => void; +} + +export function EditGame({ onShowToast }: Props) { + const { title } = useParams<{ title: string }>(); + const navigate = useNavigate(); + const [game, setGame] = useState<Game | null>(null); + const [newTitle, setNewTitle] = useState(""); + const [source, setSource] = useState<Source>(Source.STEAM); + const [minPlayers, setMinPlayers] = useState(1); + const [maxPlayers, setMaxPlayers] = useState(1); + const [price, setPrice] = useState(0); + const [remoteId, setRemoteId] = useState(0); + const [isSubmitting, setIsSubmitting] = useState(false); + const [remoteIdError, setRemoteIdError] = useState(""); + const [loading, setLoading] = useState(true); + + useEffect(() => { + if (!title) return; + + apiFetch(`/api/game/${encodeURIComponent(title)}`) + .then(async (res) => { + if (!res.ok) throw new Error("Game not found"); + return Game.decode(new Uint8Array(await res.arrayBuffer())); + }) + .then((data) => { + setGame(data); + setNewTitle(data.title); + setSource(data.source); + setMinPlayers(data.minPlayers); + setMaxPlayers(data.maxPlayers); + setPrice(data.price); + setRemoteId(data.remoteId); + setLoading(false); + }) + .catch((err) => { + console.error(err); + onShowToast?.("Failed to load game", "error"); + setLoading(false); + }); + }, [title, onShowToast]); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + if (remoteId === 0) { + setRemoteIdError("Remote ID must be greater than 0"); + return; + } + + if (!newTitle.trim()) { + onShowToast?.("Game title is required", "error"); + return; + } + + setRemoteIdError(""); + setIsSubmitting(true); + const updatedGame = { + title: newTitle.trim(), + source, + minPlayers, + maxPlayers, + price, + remoteId, + }; + + try { + const encoded = Game.encode(updatedGame).finish(); + const res = await apiFetch("/api/game", { + method: "PATCH", + headers: { + "Content-Type": "application/octet-stream", + }, + body: encoded, + }); + + if (res.ok) { + onShowToast?.("Game updated successfully!", "success"); + navigate(`/game/${encodeURIComponent(newTitle.trim())}`); + } else { + onShowToast?.("Failed to update game. Please try again.", "error"); + } + } catch (err) { + console.error(err); + onShowToast?.("An error occurred while updating the game.", "error"); + } finally { + setIsSubmitting(false); + } + }; + + if (loading) return <div>Loading...</div>; + if (!game) return <div>Game not found</div>; + + const formCardStyles: React.CSSProperties = { + background: + "linear-gradient(135deg, var(--secondary-bg) 0%, var(--secondary-alt-bg) 100%)", + borderRadius: "20px", + padding: "0", + maxWidth: "520px", + margin: "0 auto", + boxShadow: "0 20px 40px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--border-color)", + overflow: "hidden", + }; + + const formHeaderStyles: React.CSSProperties = { + background: + "linear-gradient(135deg, var(--accent-color) 0%, var(--secondary-accent) 100%)", + padding: "1.5rem 2rem", + display: "flex", + alignItems: "center", + gap: "1rem", + }; + + const formBodyStyles: React.CSSProperties = { + padding: "2rem", + }; + + const sectionStyles: React.CSSProperties = { + marginBottom: "1.5rem", + }; + + const sectionTitleStyles: React.CSSProperties = { + fontSize: "0.75rem", + textTransform: "uppercase", + letterSpacing: "0.1em", + color: "var(--text-muted)", + marginBottom: "1rem", + display: "flex", + alignItems: "center", + gap: "0.5rem", + }; + + const inputGroupStyles: React.CSSProperties = { + position: "relative", + marginBottom: "1rem", + }; + + const labelStyles: React.CSSProperties = { + fontSize: "0.85rem", + color: "var(--text-muted)", + marginBottom: "0.5rem", + display: "block", + fontWeight: 500, + }; + + const inputStyles: React.CSSProperties = { + width: "100%", + padding: "0.875rem 1rem", + backgroundColor: "var(--tertiary-bg)", + border: "2px solid var(--border-color)", + borderRadius: "12px", + color: "var(--text-color)", + fontSize: "1rem", + transition: "all 0.2s ease", + boxSizing: "border-box", + }; + + const gridStyles: React.CSSProperties = { + display: "grid", + gridTemplateColumns: "1fr 1fr", + gap: "1rem", + }; + + const dividerStyles: React.CSSProperties = { + height: "1px", + background: + "linear-gradient(90deg, transparent, var(--border-color), transparent)", + margin: "1.5rem 0", + }; + + const buttonStyles: React.CSSProperties = { + padding: "1rem", + background: + "linear-gradient(135deg, var(--accent-color) 0%, var(--secondary-accent) 100%)", + border: "none", + borderRadius: "12px", + color: "white", + fontSize: "1rem", + fontWeight: 600, + cursor: isSubmitting ? "not-allowed" : "pointer", + transition: "all 0.3s ease", + display: "flex", + alignItems: "center", + justifyContent: "center", + gap: "0.5rem", + opacity: isSubmitting ? 0.7 : 1, + transform: isSubmitting ? "none" : undefined, + }; + + const cancelStyles: React.CSSProperties = { + ...buttonStyles, + background: "var(--tertiary-bg)", + color: "var(--text-color)", + border: "2px solid var(--border-color)", + }; + + return ( + <div> + <div style={formCardStyles}> + <div style={formHeaderStyles}> + <div + style={{ + width: "48px", + height: "48px", + borderRadius: "14px", + backgroundColor: "rgba(255, 255, 255, 0.2)", + display: "flex", + alignItems: "center", + justifyContent: "center", + fontSize: "1.5rem", + }} + > + ✏️ + </div> + <div> + <h2 + style={{ + margin: 0, + fontSize: "1.5rem", + fontWeight: 700, + color: "white", + }} + > + Edit Game + </h2> + <p + style={{ + margin: 0, + fontSize: "0.9rem", + color: "rgba(255, 255, 255, 0.8)", + }} + > + Update game information + </p> + </div> + </div> + + <div style={formBodyStyles}> + <form onSubmit={handleSubmit}> + <div style={sectionStyles}> + <div style={sectionTitleStyles}> + <span>📝</span> + Basic Information + </div> + + <div style={inputGroupStyles}> + <label style={labelStyles}>Game Title</label> + <input + type="text" + value={newTitle} + onChange={(e) => setNewTitle(e.target.value)} + required + placeholder="Enter game title..." + style={inputStyles} + className="add-game-input" + /> + </div> + + <div style={inputGroupStyles}> + <label style={labelStyles}>Platform Source</label> + <select + value={source} + onChange={(e) => setSource(Number(e.target.value))} + style={{ + ...inputStyles, + cursor: "pointer", + appearance: "none", + backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a0a0a0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E")`, + backgroundRepeat: "no-repeat", + backgroundPosition: "right 1rem center", + paddingRight: "2.5rem", + }} + className="add-game-input" + > + <option value={Source.STEAM}>🎮 Steam</option> + <option value={Source.ROBLOX}>🟢 Roblox</option> + </select> + </div> + </div> + + <div style={dividerStyles}></div> + + <div style={sectionStyles}> + <div style={sectionTitleStyles}> + <span>👥</span> + Player Count + </div> + + <div style={gridStyles}> + <div style={inputGroupStyles}> + <label style={labelStyles}>Minimum Players</label> + <input + type="number" + value={minPlayers} + onChange={(e) => setMinPlayers(Number(e.target.value))} + min="1" + style={inputStyles} + className="add-game-input" + /> + </div> + <div style={inputGroupStyles}> + <label style={labelStyles}>Maximum Players</label> + <input + type="number" + value={maxPlayers} + onChange={(e) => setMaxPlayers(Number(e.target.value))} + min="1" + style={inputStyles} + className="add-game-input" + /> + </div> + </div> + </div> + + <div style={dividerStyles}></div> + + <div style={sectionStyles}> + <div style={sectionTitleStyles}> + <span>💰</span> + Additional Details + </div> + + <div style={gridStyles}> + <div style={inputGroupStyles}> + <label style={labelStyles}>Price (€)</label> + <input + type="number" + value={price} + onChange={(e) => setPrice(Number(e.target.value))} + min="0" + step="0.01" + style={inputStyles} + className="add-game-input" + /> + </div> + <div style={inputGroupStyles}> + <label style={labelStyles}>Remote ID</label> + <input + type="number" + value={remoteId} + onChange={(e) => { + setRemoteId(Number(e.target.value)); + setRemoteIdError(""); + }} + min="0" + style={{ + ...inputStyles, + borderColor: remoteIdError ? "#f44336" : undefined, + }} + className="add-game-input" + /> + {remoteIdError && ( + <div + style={{ + color: "#f44336", + fontSize: "0.75rem", + marginTop: "0.25rem", + }} + > + {remoteIdError} + </div> + )} + </div> + </div> + </div> + + <div style={gridStyles}> + <button + type="button" + onClick={() => navigate(`/game/${encodeURIComponent(game.title)}`)} + disabled={isSubmitting} + style={cancelStyles} + > + Cancel + </button> + <button + type="submit" + disabled={isSubmitting} + style={buttonStyles} + > + {isSubmitting ? ( + <>Updating...</> + ) : ( + <> + <span style={{ fontSize: "1.1rem" }}>💾</span> + Save Changes + </> + )} + </button> + </div> + </form> + </div> + </div> + </div> + ); +} diff --git a/frontend/src/GameDetails.tsx b/frontend/src/GameDetails.tsx index 68bba3e..db45b98 100644 --- a/frontend/src/GameDetails.tsx +++ b/frontend/src/GameDetails.tsx @@ -1,13 +1,20 @@ import { useState, useEffect } from "react"; -import { useParams } from "react-router-dom"; +import { useParams, useNavigate } from "react-router-dom"; import { Game, Source } from "../items"; -import { apiFetch } from "./api"; +import { apiFetch, get_is_admin } from "./api"; -export function GameDetails() { +interface Props { + onShowToast?: (message: string, type?: "success" | "error" | "info") => void; +} + +export function GameDetails({ onShowToast }: Props) { const { title } = useParams<{ title: string }>(); + const navigate = useNavigate(); const [game, setGame] = useState<Game | null>(null); const [loading, setLoading] = useState(true); + const isAdmin = get_is_admin(); + useEffect(() => { if (!title) return; @@ -26,6 +33,32 @@ export function GameDetails() { }); }, [title]); + const handleDelete = async () => { + if ( + !confirm( + `Are you sure you want to delete "${game?.title}"? This action cannot be undone.` + ) + ) { + return; + } + + try { + const res = await apiFetch(`/api/game/${encodeURIComponent(title || "")}`, { + method: "DELETE", + }); + + if (res.ok) { + onShowToast?.(`"${game?.title}" deleted successfully`, "success"); + navigate("/games"); + } else { + onShowToast?.("Failed to delete game", "error"); + } + } catch (err) { + console.error(err); + onShowToast?.("An error occurred while deleting the game", "error"); + } + }; + if (loading) return <div>Loading...</div>; if (!game) return <div>Game not found</div>; @@ -40,7 +73,39 @@ export function GameDetails() { return ( <div className="card" style={{ maxWidth: "600px", margin: "0 auto" }}> - <h2>{game.title}</h2> + <div + style={{ + display: "flex", + justifyContent: "space-between", + alignItems: "center", + marginBottom: "1rem", + }} + > + <h2 style={{ margin: 0 }}>{game.title}</h2> + {isAdmin && ( + <div style={{ display: "flex", gap: "0.5rem" }}> + <button + onClick={() => navigate(`/game/${encodeURIComponent(game.title)}/edit`)} + className="btn-secondary" + style={{ padding: "0.5rem 1rem", fontSize: "0.9rem" }} + > + ✏️ Edit + </button> + <button + onClick={handleDelete} + className="btn-primary" + style={{ + padding: "0.5rem 1rem", + fontSize: "0.9rem", + background: "#f44336", + border: "none", + }} + > + 🗑️ Delete + </button> + </div> + )} + </div> <div style={{ display: "grid", gap: "1rem", marginTop: "1rem" }}> <div> <strong>Source:</strong>{" "} diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 1e06bd7..18dad73 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -21,6 +21,7 @@ export const apiFetch = async ( if (!response.ok) { if (response.status == 401) { localStorage.removeItem("token"); + localStorage.removeItem("isAdmin"); window.location.href = "/"; } throw new Error(`Request failed with status ${response.status}`); @@ -43,9 +44,14 @@ export const get_auth_status = async (): Promise<AuthStatusResponse | null> => { const buffer = await response.arrayBuffer(); try { const response = AuthStatusResponse.decode(new Uint8Array(buffer)); + localStorage.setItem("isAdmin", String(response.isAdmin)); return response; } catch (e) { console.error("Failed to decode auth status:", e); return null; } }; + +export const get_is_admin = (): boolean => { + return localStorage.getItem("isAdmin") === "true"; +}; diff --git a/protobuf/items.proto b/protobuf/items.proto index 385013e..6729cf9 100644 --- a/protobuf/items.proto +++ b/protobuf/items.proto @@ -56,6 +56,7 @@ message AuthStatusResponse { bool authenticated = 1; string username = 2; string message = 3; + bool isAdmin = 4; } // Authentication service