firebase_user/
sign_up.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    error::{ApiError, check_response},
5    url::FirebaseUrl,
6};
7
8pub async fn by_email(
9    firebase_url: &FirebaseUrl,
10    email: &str,
11    password: &str,
12    return_secure_token: bool,
13) -> Result<SignUpByEmailResponse, ApiError> {
14    let client = reqwest::Client::new();
15
16    let response = client
17        .post(&firebase_url.sign_up_by_email_url)
18        .header("Content-Type", "application/json")
19        .json(&Payload {
20            email,
21            password,
22            return_secure_token,
23        })
24        .send()
25        .await?;
26
27    check_response(response).await
28}
29
30#[derive(Debug, Serialize)]
31#[serde(rename_all = "camelCase")]
32struct Payload<'a> {
33    email: &'a str,
34    password: &'a str,
35    return_secure_token: bool,
36}
37
38#[derive(Debug, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct SignUpByEmailResponse {
41    pub id_token: String,
42    pub email: String,
43    pub refresh_token: String,
44    pub expires_in: String,
45    pub local_id: String,
46}