create_user/
create_user.rs1use anyhow::Result;
19use privy_rs::{
20 PrivyClient,
21 generated::types::{
22 CreateUserBody, LinkedAccountCustomJwtInput, LinkedAccountCustomJwtInputType,
23 LinkedAccountEmailInput, LinkedAccountEmailInputType, LinkedAccountInput,
24 },
25};
26use tracing_subscriber::EnvFilter;
27
28#[tokio::main]
29async fn main() -> Result<()> {
30 tracing_subscriber::fmt()
31 .with_env_filter(
32 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
33 )
34 .init();
35
36 let client = PrivyClient::new_from_env()?;
38
39 tracing::info!("initialized privy client from environment");
40
41 let user = client
42 .users()
43 .create(&CreateUserBody {
44 linked_accounts: vec![
45 LinkedAccountInput::EmailInput(LinkedAccountEmailInput {
46 address: "alex@arlyon.dev".into(),
47 type_: LinkedAccountEmailInputType::Email,
48 }),
49 LinkedAccountInput::CustomJwtInput(LinkedAccountCustomJwtInput {
50 custom_user_id: "alex@arlyon.dev".try_into().unwrap(),
51 type_: LinkedAccountCustomJwtInputType::CustomAuth,
52 }),
53 ],
54 custom_metadata: None,
55 wallets: vec![],
56 })
57 .await?;
58
59 tracing::info!("got new user: {:?}", user);
60
61 Ok(())
62}