upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/login')
-rw-r--r--src/lib/login/mod.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs
index 6fa8a16..b6e7623 100644
--- a/src/lib/login/mod.rs
+++ b/src/lib/login/mod.rs
@@ -56,7 +56,7 @@ pub async fn launch(
56 .to_string() 56 .to_string()
57 .eq("git config item nostr.nsec is an ncryptsec") 57 .eq("git config item nostr.nsec is an ncryptsec")
58 { 58 {
59 println!( 59 eprintln!(
60 "login as {}", 60 "login as {}",
61 if let Ok(public_key) = PublicKey::from_bech32( 61 if let Ok(public_key) = PublicKey::from_bech32(
62 get_config_item(git_repo, "nostr.npub") 62 get_config_item(git_repo, "nostr.npub")
@@ -82,7 +82,7 @@ pub async fn launch(
82 if let Ok(keys) = get_keys_with_password(git_repo, &password) { 82 if let Ok(keys) = get_keys_with_password(git_repo, &password) {
83 break Ok(NostrSigner::Keys(keys)); 83 break Ok(NostrSigner::Keys(keys));
84 } 84 }
85 println!("incorrect password"); 85 eprintln!("incorrect password");
86 } 86 }
87 } else { 87 } else {
88 if nsec.is_some() { 88 if nsec.is_some() {
@@ -107,8 +107,6 @@ pub async fn launch(
107 print_logged_in_as(&user_ref, client.is_none())?; 107 print_logged_in_as(&user_ref, client.is_none())?;
108 } 108 }
109 Ok((signer, user_ref)) 109 Ok((signer, user_ref))
110 } else if silent {
111 bail!("TODO: enable interactive login in nostr git remote helper");
112 } else { 110 } else {
113 fresh_login(git_repo, client, change_user).await 111 fresh_login(git_repo, client, change_user).await
114 } 112 }
@@ -116,15 +114,15 @@ pub async fn launch(
116 114
117fn print_logged_in_as(user_ref: &UserRef, offline_mode: bool) -> Result<()> { 115fn print_logged_in_as(user_ref: &UserRef, offline_mode: bool) -> Result<()> {
118 if !offline_mode && user_ref.metadata.created_at.eq(&Timestamp::from(0)) { 116 if !offline_mode && user_ref.metadata.created_at.eq(&Timestamp::from(0)) {
119 println!("cannot find profile..."); 117 eprintln!("cannot find profile...");
120 } else if !offline_mode && user_ref.metadata.name.eq(&user_ref.public_key.to_bech32()?) { 118 } else if !offline_mode && user_ref.metadata.name.eq(&user_ref.public_key.to_bech32()?) {
121 println!("cannot extract account name from account metadata..."); 119 eprintln!("cannot extract account name from account metadata...");
122 } else if !offline_mode && user_ref.relays.created_at.eq(&Timestamp::from(0)) { 120 } else if !offline_mode && user_ref.relays.created_at.eq(&Timestamp::from(0)) {
123 println!( 121 eprintln!(
124 "cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience." 122 "cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience."
125 ); 123 );
126 } 124 }
127 println!("logged in as {}", user_ref.metadata.name); 125 eprintln!("logged in as {}", user_ref.metadata.name);
128 Ok(()) 126 Ok(())
129} 127}
130 128
@@ -219,25 +217,25 @@ fn save_to_git_config(
219 global: bool, 217 global: bool,
220) -> Result<()> { 218) -> Result<()> {
221 if let Err(error) = silently_save_to_git_config(git_repo, npub, nsec, bunker, global) { 219 if let Err(error) = silently_save_to_git_config(git_repo, npub, nsec, bunker, global) {
222 println!( 220 eprintln!(
223 "failed to save login details to {} git config", 221 "failed to save login details to {} git config",
224 if global { "global" } else { "local" } 222 if global { "global" } else { "local" }
225 ); 223 );
226 if let Some(nsec) = nsec { 224 if let Some(nsec) = nsec {
227 if nsec.contains("ncryptsec") { 225 if nsec.contains("ncryptsec") {
228 println!("manually set git config nostr.nsec to: {nsec}"); 226 eprintln!("manually set git config nostr.nsec to: {nsec}");
229 } else { 227 } else {
230 println!("manually set git config nostr.nsec"); 228 eprintln!("manually set git config nostr.nsec");
231 } 229 }
232 } 230 }
233 if let Some(bunker) = bunker { 231 if let Some(bunker) = bunker {
234 println!("manually set git config as follows:"); 232 eprintln!("manually set git config as follows:");
235 println!("nostr.bunker-uri: {}", bunker.0); 233 eprintln!("nostr.bunker-uri: {}", bunker.0);
236 println!("nostr.bunker-app-key: {}", bunker.1); 234 eprintln!("nostr.bunker-app-key: {}", bunker.1);
237 } 235 }
238 Err(error) 236 Err(error)
239 } else { 237 } else {
240 println!( 238 eprintln!(
241 "saved login details to {} git config", 239 "saved login details to {} git config",
242 if global { "global" } else { "local" } 240 if global { "global" } else { "local" }
243 ); 241 );
@@ -367,7 +365,7 @@ async fn fresh_login(
367 .context("failed to get nsec input from interactor")?; 365 .context("failed to get nsec input from interactor")?;
368 if let Ok(keys) = nostr::Keys::from_str(&input) { 366 if let Ok(keys) = nostr::Keys::from_str(&input) {
369 if let Err(error) = save_keys(git_repo, &keys, always_save) { 367 if let Err(error) = save_keys(git_repo, &keys, always_save) {
370 println!("{error}"); 368 eprintln!("{error}");
371 } 369 }
372 break NostrSigner::Keys(keys); 370 break NostrSigner::Keys(keys);
373 } 371 }
@@ -391,7 +389,7 @@ async fn fresh_login(
391 if let Err(error) = 389 if let Err(error) =
392 save_bunker(git_repo, &pub_key, &uri.to_string(), &app_key, always_save) 390 save_bunker(git_repo, &pub_key, &uri.to_string(), &app_key, always_save)
393 { 391 {
394 println!("{error}"); 392 eprintln!("{error}");
395 } 393 }
396 public_key = Some(pub_key); 394 public_key = Some(pub_key);
397 break signer; 395 break signer;
@@ -420,7 +418,7 @@ pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result<NostrConnectURI>
420 match res { 418 match res {
421 Ok(profile) => { 419 Ok(profile) => {
422 if profile.nip46.is_empty() { 420 if profile.nip46.is_empty() {
423 println!("nip05 provider isn't configured for remote login"); 421 eprintln!("nip05 provider isn't configured for remote login");
424 bail!("nip05 provider isn't configured for remote login") 422 bail!("nip05 provider isn't configured for remote login")
425 } 423 }
426 Ok(NostrConnectURI::Bunker { 424 Ok(NostrConnectURI::Bunker {
@@ -430,7 +428,7 @@ pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result<NostrConnectURI>
430 }) 428 })
431 } 429 }
432 Err(error) => { 430 Err(error) => {
433 println!("error contacting login service provider: {error}"); 431 eprintln!("error contacting login service provider: {error}");
434 Err(error).context("error contacting login service provider") 432 Err(error).context("error contacting login service provider")
435 } 433 }
436 } 434 }