@smbcloud / cli / commits / 5dd2ad2

Prevent signup when already logged in

Seto Elkahfi committed Sep 13, 2023 at 19:59 UTC 5dd2ad202c8eb6b1a368c9f9eb4ff77ec0c80dcd
2 files changed +14 -2
smbpndk-cli/src/account/login/process.rs
+1 -1
@@ -49,7 +49,7 @@ pub async fn process_login() -> Result<CommandResult> {
49 style("Loading...").green().bold().to_string(),
50 ),
51 symbol: "✅".to_owned(),
52 - msg: "You are already logged in.".to_owned(),
52 + msg: "You are already logged in. Please logout first.".to_owned(),
53 });
54 }
55
smbpndk-cli/src/account/signup/process.rs
+13 -1
@@ -11,7 +11,7 @@ use reqwest::{Client, StatusCode};
11 use serde::{Deserialize, Serialize};
12 use smbpndk_model::CommandResult;
13
14 -use smbpndk_networking::smb_base_url_builder;
14 +use smbpndk_networking::{smb_base_url_builder, smb_token_file_path};
15 use smbpndk_utils::email_validation;
16 use spinners::Spinner;
17 use std::fmt::{Display, Formatter};
@@ -58,6 +58,18 @@ struct SignupResult {
58 }
59
60 pub async fn process_signup() -> Result<CommandResult> {
61 + // Check if token file exists
62 + if smb_token_file_path().is_some() {
63 + return Ok(CommandResult {
64 + spinner: Spinner::new(
65 + spinners::Spinners::SimpleDotsScrolling,
66 + style("Loading...").green().bold().to_string(),
67 + ),
68 + symbol: "✅".to_owned(),
69 + msg: "You are already logged in. Please logout first.".to_owned(),
70 + });
71 + }
72 +
73 let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];
74 let selection = Select::with_theme(&ColorfulTheme::default())
75 .items(&signup_methods)