diff --git "a/#[cfg(feature = \"server\")]\npub mod pool;\n\n#[cfg(not(feature = \"server\"))]\npub mod pool {\n pub static DB_POOL: () = ();\n}" "b/#[cfg(feature = \"server\")]\npub mod pool;\n\n#[cfg(not(feature = \"server\"))]\npub mod pool {\n pub static DB_POOL: () = ();\n}" new file mode 100644 index 0000000..9024c08 --- /dev/null +++ "b/#[cfg(feature = \"server\")]\npub mod pool;\n\n#[cfg(not(feature = \"server\"))]\npub mod pool {\n pub static DB_POOL: () = ();\n}" @@ -0,0 +1 @@ +/home/xfy/Developer/yggdrasil/src/db/mod.rs \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index fd410ab..7fa0b68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4594,12 +4594,14 @@ dependencies = [ "deadpool-postgres", "dioxus", "dotenvy", + "getrandom 0.2.17", "rand 0.8.6", "regex", "serde", "tokio", "tokio-postgres", "uuid", + "wasm-bindgen", "web-sys", ] diff --git a/Cargo.toml b/Cargo.toml index a15d473..6d8d94e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,17 @@ serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.52", features = ["full"], optional = true } tokio-postgres = { version = "0.7", features = ["with-chrono-0_4"], optional = true } deadpool-postgres = { version = "0.14", optional = true } -argon2 = { version = "0.5", optional = true } -uuid = { version = "1", features = ["v4"], optional = true } -chrono = { version = "0.4", features = ["serde"], optional = true } -regex = { version = "1.10", optional = true } +argon2 = "0.5" +uuid = { version = "1", features = ["v4", "js"] } +chrono = { version = "0.4", features = ["serde"] } +regex = "1.10" dotenvy = { version = "0.15", optional = true } -rand = { version = "0.8", features = ["getrandom"], optional = true } +rand = { version = "0.8", features = ["getrandom"] } +getrandom = { version = "0.2", features = ["js"] } [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = ["Document", "Window", "HtmlDocument", "Storage", "Element"] } +wasm-bindgen = "0.2" [features] default = [] @@ -27,10 +29,5 @@ server = [ "dep:tokio", "dep:tokio-postgres", "dep:deadpool-postgres", - "dep:argon2", - "dep:uuid", - "dep:chrono", - "dep:regex", "dep:dotenvy", - "dep:rand", ] diff --git a/migrations/001_init.sql b/migrations/001_init.sql index bffce08..228323e 100644 --- a/migrations/001_init.sql +++ b/migrations/001_init.sql @@ -1,11 +1,9 @@ -CREATE TYPE user_role AS ENUM ('admin', 'blocked'); - CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, username VARCHAR(50) UNIQUE NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, - role user_role NOT NULL DEFAULT 'blocked', + role VARCHAR(20) NOT NULL DEFAULT 'blocked', created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); diff --git a/src/db/mod.rs b/src/db/mod.rs index c9e2bb1..0cc510a 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1 +1,13 @@ +#[cfg(feature = "server")] pub mod pool; + +#[cfg(not(feature = "server"))] +pub mod pool { + pub struct DummyPool; + impl DummyPool { + pub async fn get(&self) -> Result<(), ()> { + Err(()) + } + } + pub static DB_POOL: DummyPool = DummyPool; +} diff --git a/src/main.rs b/src/main.rs index 68eea3f..5b59912 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,10 @@ fn main() { #[cfg(feature = "server")] { dotenvy::dotenv().ok(); - tokio::spawn(tasks::session_cleanup::run_cleanup()); + std::thread::spawn(|| { + let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime"); + rt.block_on(tasks::session_cleanup::run_cleanup()); + }); } dioxus::launch(AppRouter); diff --git a/src/pages/admin.rs b/src/pages/admin.rs index fade38b..231fbce 100644 --- a/src/pages/admin.rs +++ b/src/pages/admin.rs @@ -1,5 +1,8 @@ use dioxus::prelude::*; +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::JsCast; + use crate::api::auth::{get_current_user, logout}; #[component] diff --git a/src/pages/login.rs b/src/pages/login.rs index e5563b5..fec0ea1 100644 --- a/src/pages/login.rs +++ b/src/pages/login.rs @@ -1,5 +1,8 @@ use dioxus::prelude::*; +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::JsCast; + use crate::api::auth::{login, AuthResponse}; #[component] diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index b4501c3..5b016c6 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -1 +1,2 @@ +#[cfg(feature = "server")] pub mod session_cleanup;