login system

This commit is contained in:
2025-07-14 20:27:18 +02:00
parent 2da5c1e9e2
commit 1cb0b44510
5 changed files with 41 additions and 9 deletions
+23
View File
@@ -0,0 +1,23 @@
use dioxus::prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct User {
username: String,
password: String,
}
#[server]
pub async fn login(username: String, password: String) -> Result<String, ServerFnError> {
let users = crate::backend::get_mongo::<User>("users").await?;
match users
.find_one(mongodb::bson::doc! {
"username": username,
"password": password,
})
.await?
{
Some(v) => Ok(String::new()),
None => Err(ServerFnError::new(format!("Invalid credentials"))),
}
}