Minor Bugfixes
This commit is contained in:
@@ -12,7 +12,11 @@ use axum_extra::extract::CookieJar;
|
|||||||
use jsonwebtoken::DecodingKey;
|
use jsonwebtoken::DecodingKey;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{AppState, cookie::jwt::decode_token, models::LoginModel};
|
use crate::{
|
||||||
|
AppState,
|
||||||
|
cookie::jwt::decode_token,
|
||||||
|
models::{LoginScheme, User},
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn validate_token(
|
pub async fn validate_token(
|
||||||
cookies: CookieJar,
|
cookies: CookieJar,
|
||||||
@@ -59,7 +63,7 @@ pub async fn validate_token(
|
|||||||
(StatusCode::UNAUTHORIZED, Json(error))
|
(StatusCode::UNAUTHORIZED, Json(error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let user = sqlx::query_as::<_, LoginModel>(r#"SELECT * FROM users WHERE id = $1"#)
|
let user = sqlx::query_as::<_, User>(r#"SELECT * FROM users WHERE id = $1"#)
|
||||||
.bind(uuid)
|
.bind(uuid)
|
||||||
.fetch_optional(&data.db)
|
.fetch_optional(&data.db)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
pub struct Env {
|
pub struct Env {
|
||||||
pub db_url: String,
|
pub db_url: String,
|
||||||
pub token_secret: String,
|
pub token_secret: String,
|
||||||
pub origin: String
|
pub origin: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Env {
|
impl Env {
|
||||||
pub fn load() -> Env {
|
pub fn load() -> Env {
|
||||||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||||
let token_secret = std::env::var("TOKEN_SECRET").expect("TOKEN_SECRET must be set");
|
let token_secret = std::env::var("TOKEN_SECRET").expect("TOKEN_SECRET must be set");
|
||||||
let origin = std::env::var("ORIGIN").expect("ORIGIN must be set")
|
let origin = std::env::var("ORIGIN").expect("ORIGIN must be set");
|
||||||
Env {
|
Env {
|
||||||
db_url,
|
db_url,
|
||||||
token_secret,
|
token_secret,
|
||||||
origin
|
origin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
frontend/Cargo.lock
generated
46
frontend/Cargo.lock
generated
@@ -70,6 +70,7 @@ dependencies = [
|
|||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"yew",
|
"yew",
|
||||||
|
"yew-router",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -219,6 +220,7 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97563d71863fb2824b2e974e754a81d19c4a7ec47b09ced8a0e6656b6d54bd1f"
|
checksum = "97563d71863fb2824b2e974e754a81d19c4a7ec47b09ced8a0e6656b6d54bd1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"gloo-events",
|
"gloo-events",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
@@ -315,6 +317,8 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994"
|
checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
@@ -590,6 +594,12 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "route-recognizer"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.22"
|
version = "1.0.22"
|
||||||
@@ -838,6 +848,12 @@ version = "1.0.24"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urlencoding"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
@@ -963,6 +979,36 @@ dependencies = [
|
|||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yew-router"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "870bd2a1aa6d608c0c789c122654e25f4927bb6bfe344cc0da3b630ac3c73260"
|
||||||
|
dependencies = [
|
||||||
|
"gloo",
|
||||||
|
"js-sys",
|
||||||
|
"route-recognizer",
|
||||||
|
"serde",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"tracing",
|
||||||
|
"urlencoding",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"web-sys",
|
||||||
|
"yew",
|
||||||
|
"yew-router-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yew-router-macro"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8399f1d134ab8e69abc7cded19f114621d520bd9c79c5a0f34091bf664d7325b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ wasm-bindgen = "0.2.118"
|
|||||||
wasm-bindgen-futures = "0.4.68"
|
wasm-bindgen-futures = "0.4.68"
|
||||||
web-sys = { version = "0.3.95", features = ["Window", "Document", "Request", "Response", "Headers"] }
|
web-sys = { version = "0.3.95", features = ["Window", "Document", "Request", "Response", "Headers"] }
|
||||||
gloo-net = "0.7.0"
|
gloo-net = "0.7.0"
|
||||||
|
yew-router = "0.20.0"
|
||||||
|
|||||||
@@ -1,20 +1,29 @@
|
|||||||
|
mod pages;
|
||||||
|
use crate::pages::*;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
use yew_router::prelude::*;
|
||||||
|
|
||||||
#[function_component]
|
#[derive(Clone, PartialEq, Routable)]
|
||||||
pub fn App() -> Html {
|
enum Route {
|
||||||
let counter = use_state(|| 0);
|
#[at("/")]
|
||||||
let onclick = {
|
Home,
|
||||||
let counter = counter.clone();
|
#[not_found]
|
||||||
move |_| {
|
#[at("/404")]
|
||||||
let value = *counter + 1;
|
NotFound,
|
||||||
counter.set(value);
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
html! {
|
fn switch(route: Route) -> Html {
|
||||||
<div>
|
match route {
|
||||||
<button {onclick}>{ "+1" }</button>
|
Route::Home => html! { <basic_pages::Home/>},
|
||||||
<p>{ *counter }</p>
|
Route::NotFound => html! { <basic_pages::Home/> },
|
||||||
</div>
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component(App)]
|
||||||
|
pub fn app() -> Html {
|
||||||
|
html! {
|
||||||
|
<BrowserRouter>
|
||||||
|
<Switch<Route> render={switch} />
|
||||||
|
</BrowserRouter>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
frontend/src/pages/basic_pages.rs
Normal file
30
frontend/src/pages/basic_pages.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use yew::prelude::*;
|
||||||
|
|
||||||
|
#[component(Home)]
|
||||||
|
pub fn home_component() -> Html {
|
||||||
|
let counter = use_state(|| 0);
|
||||||
|
let onclick = {
|
||||||
|
let counter = counter.clone();
|
||||||
|
move |_| {
|
||||||
|
let value = *counter + 1;
|
||||||
|
counter.set(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
html! {
|
||||||
|
<div>
|
||||||
|
<button {onclick}>{ "+1" }</button>
|
||||||
|
<p>{ *counter }</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component(NotFound)]
|
||||||
|
pub fn not_found_component() -> Html {
|
||||||
|
let message = "404 Not found";
|
||||||
|
html! {
|
||||||
|
<div>
|
||||||
|
<h1>{&message}</h1>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
1
frontend/src/pages/mod.rs
Normal file
1
frontend/src/pages/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod basic_pages;
|
||||||
Reference in New Issue
Block a user