pub async fn signup_user(
db: &DB,
username: &str,
email: Option<&str>,
password: &str,
email_backup_codes: Option<Vec<String>>,
) -> Result<User, Box<dyn Error + Send + Sync>>Expand description
Creates a new user account in the database
§Arguments
db- A reference to the database connectionusername- The desired username for the new accountemail- An optional email address for the new accountpassword_hash- The hashed password for the new account
§Returns
Ok(User)- The newly created user object if the operation was successfulErr(Box<dyn Error>)- An error if the operation failed, such as if the username is already taken or if there was a database error
§Errors
- “Failed to create user” - If the database query did not return a user object, indicating that the user creation failed
§Example
use crate::db::DB;
use crate::db::queries::auth;
async fn example_signup(db: &DB) {
let username = "new_user";
let email = Some("123@example.com");
let password_hash = "hashed_password";
match auth::signup_user(db, username, email, password_hash).await {
Ok(user) => println!("User created: {:?}", user),
Err(e) => eprintln!("Error creating user: {}", e),
}
}