-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_with_email_password.rs
56 lines (46 loc) · 1.22 KB
/
link_with_email_password.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! An example to link with email and password by session-based interface.
//!
//! ```shell
//! $ cargo run --example link_with_email_password -- --email <email> --password <password>
//! ```
use clap::Parser;
use fars::ApiKey;
use fars::Config;
use fars::Email;
use fars::Password;
#[derive(Parser)]
struct Arguments {
#[arg(short, long)]
email: String,
#[arg(short, long)]
password: String,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Parse the command line arguments.
let arguments = Arguments::parse();
// Read API key from the environment variable.
let api_key = ApiKey::from_env()?;
// Create a config.
let config = Config::new(api_key);
// Get a session by signing in anonymously.
let session = config
.sign_in_anonymously()
.await?;
// Link email and password.
let session = session
.link_with_email_password(
Email::new(arguments.email.clone()),
Password::new(arguments.password.clone()),
)
.await?;
println!(
"Succeeded to link with email/password: {:?}",
session
);
// Delete the anonymous account.
session
.delete_account()
.await?;
Ok(())
}