firebase_user/api/
sign_up.rs1use super::FailResponse;
2use crate::error::Error;
3use serde::{Deserialize, Serialize};
4
5impl crate::FireAuth {
6 pub async fn sign_up_email(
7 &self,
8 email: &str,
9 password: &str,
10 return_secure_token: bool,
11 ) -> Result<Response, Error> {
12 let url = format!(
13 "https://identitytoolkit.googleapis.com/v1/accounts:signUp?key={}",
14 self.api_key,
15 );
16
17 let client = reqwest::Client::new();
18 let resp = client
19 .post(&url)
20 .header("Content-Type", "application/json")
21 .json(&SignUpPayload {
22 email,
23 password,
24 return_secure_token,
25 })
26 .send()
27 .await?;
28
29 if resp.status() != 200 {
30 let error = resp.json::<FailResponse>().await?.error;
31 return Err(Error::SignUp(error.message));
32 }
33 let body = resp.json::<Response>().await?;
34 Ok(body)
35 }
36}
37
38#[derive(Debug, Serialize)]
39#[serde(rename_all = "camelCase")]
40struct SignUpPayload<'a> {
41 email: &'a str,
42 password: &'a str,
43 return_secure_token: bool,
44}
45
46#[derive(Debug, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct Response {
49 pub id_token: String,
50 pub email: String,
51 pub refresh_token: String,
52 pub expires_in: String,
53 pub local_id: String,
54}