From bc94c6024018b5c556b6925b0f1621dfe2f0958f Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 31 Mar 2024 00:49:06 -0400 Subject: [PATCH] Fix unused NoCustomError import --- src/auth.rs | 5 ++++- src/users.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 6de6f3f..63d107a 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,5 +1,5 @@ use leptos::*; -use leptos::server_fn::error::NoCustomError; + use crate::models::User; /// Create a new user and log them in @@ -12,6 +12,7 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> { use leptos_actix::extract; use actix_web::{HttpMessage, HttpRequest}; use actix_identity::Identity; + use leptos::server_fn::error::NoCustomError; // Ensure the user has no id let new_user = User { @@ -42,6 +43,7 @@ pub async fn login(username_or_email: String, password: String) -> Result::ServerError(format!("Error validating user: {}", e)))?; @@ -68,6 +70,7 @@ pub async fn login(username_or_email: String, password: String) -> Result Result<(), ServerFnError> { use leptos_actix::extract; use actix_identity::Identity; + use leptos::server_fn::error::NoCustomError; match extract::>().await { Ok(Some(user)) => user.logout(), diff --git a/src/users.rs b/src/users.rs index e1ab382..51fecdc 100644 --- a/src/users.rs +++ b/src/users.rs @@ -14,7 +14,6 @@ cfg_if::cfg_if! { } use leptos::*; -use leptos::server_fn::error::NoCustomError; use crate::models::User; /// Get a user from the database by username or email @@ -22,6 +21,7 @@ use crate::models::User; #[cfg(feature = "ssr")] pub async fn find_user(username_or_email: String) -> Result, ServerFnError> { use crate::schema::users::dsl::*; + use leptos::server_fn::error::NoCustomError; // Look for either a username or email that matches the input, and return an option with None if no user is found let db_con = &mut get_db_conn(); @@ -37,6 +37,7 @@ pub async fn find_user(username_or_email: String) -> Result, Server #[cfg(feature = "ssr")] pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> { use crate::schema::users::dsl::*; + use leptos::server_fn::error::NoCustomError; let new_password = new_user.password.clone() .ok_or(ServerFnError::::ServerError(format!("No password provided for user {}", new_user.username)))?; @@ -62,6 +63,8 @@ pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> { /// Returns a Result with the user if the credentials are valid, None if not valid, or an error if there was a problem #[cfg(feature = "ssr")] pub async fn validate_user(username_or_email: String, password: String) -> Result, ServerFnError> { + use leptos::server_fn::error::NoCustomError; + let db_user = find_user(username_or_email.clone()).await .map_err(|e| ServerFnError::::ServerError(format!("Error getting user from database: {}", e)))?;