use serde::{Deserialize, Serialize};
use crate::{
error::{ApiError, check_response},
url::FirebaseUrl,
};
pub async fn by_email(
firebase_url: &FirebaseUrl,
email: &str,
password: &str,
return_secure_token: bool,
) -> Result<SignUpByEmailResponse, ApiError> {
let client = reqwest::Client::new();
let response = client
.post(&firebase_url.sign_up_by_email_url)
.header("Content-Type", "application/json")
.json(&Payload {
email,
password,
return_secure_token,
})
.send()
.await?;
check_response(response).await
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct Payload<'a> {
email: &'a str,
password: &'a str,
return_secure_token: bool,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SignUpByEmailResponse {
pub id_token: String,
pub email: String,
pub refresh_token: String,
pub expires_in: String,
pub local_id: String,
}