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