diff --git a/Cargo.lock b/Cargo.lock index cdccbaa..e98619b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,6 +105,7 @@ name = "backend" version = "0.1.0" dependencies = [ "bcrypt", + "bincode", "bytes", "prost", "prost-build", @@ -139,6 +140,26 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" +[[package]] +name = "bincode" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" +dependencies = [ + "bincode_derive", + "serde", + "unty", +] + +[[package]] +name = "bincode_derive" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" +dependencies = [ + "virtue", +] + [[package]] name = "bitflags" version = "2.10.0" @@ -2012,6 +2033,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "unty" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" + [[package]] name = "uuid" version = "1.18.1" @@ -2035,6 +2062,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "virtue" +version = "0.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index a2eac1e..15f612f 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -11,6 +11,7 @@ bytes = "1" rocket_prost_responder_derive = { path = "rocket_prost_responder_derive" } uuid = { version = "1.10.0", features = ["v4"] } bcrypt = "0.17.1" +bincode = "2.0.1" [build-dependencies] prost-build = "0.14.1" diff --git a/backend/src/main.rs b/backend/src/main.rs index 7565938..b100b64 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,3 +1,4 @@ +use bincode::{Decode, Encode}; use rocket::fs::FileServer; use std::sync::Mutex; @@ -31,7 +32,7 @@ impl std::ops::Deref for User { fn get_user( _token: auth::Token, user_list: &rocket::State>>, - name: String, + name: &str, ) -> Option { let users = user_list.lock().unwrap(); users @@ -55,7 +56,7 @@ fn get_users( fn get_game( _token: auth::Token, game_list: &rocket::State>, - title: String, + title: &str, ) -> Option { game_list.iter().find(|g| g.title == title).cloned() } @@ -102,8 +103,8 @@ async fn index_fallback() -> Option { None } -#[launch] -fn rocket() -> _ { +#[rocket::main] +async fn main() -> Result<(), std::io::Error> { let mut game_list: Vec = Vec::new(); let mut user_list: Vec = Vec::new(); @@ -139,4 +140,9 @@ fn rocket() -> _ { ) .mount("/", routes![index_fallback]) .mount("/", FileServer::new("frontend/dist")) + .launch() + .await + .map_err(|e| std::io::Error::other(e.to_string()))?; + + Ok(()) } diff --git a/frontend/src/api.ts b/frontend/src/api.ts index fdb3ef7..545c1c3 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -17,6 +17,10 @@ export const apiFetch = async ( const response = await fetch(url, config); if (!response.ok) { + if (response.status == 401) { + localStorage.removeItem("token"); + window.location.href = "/"; + } throw new Error(`Request failed with status ${response.status}`); }