Skip to content

Commit abf8416

Browse files
authored
feat: add interactive login prompt for unauthenticated chat command (#887)
* enfore login when chat * delete not used file * recove mcp & agent
1 parent e9c4d3d commit abf8416

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod translate;
2020
mod uninstall;
2121
mod update;
2222
mod user;
23-
2423
use std::io::{
2524
Write as _,
2625
stdout,
@@ -87,7 +86,7 @@ use crate::util::desktop::{
8786
};
8887
use crate::util::{
8988
CliContext,
90-
assert_logged_in,
89+
is_logged_in_check,
9190
};
9291

9392
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
@@ -397,8 +396,20 @@ impl Cli {
397396
}
398397

399398
pub async fn execute_chat(subcmd: &str, args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
400-
if enforce_login {
401-
assert_logged_in().await?;
399+
if enforce_login && !is_logged_in_check().await {
400+
if subcmd == "chat" {
401+
let options = ["Yes", "No"];
402+
match crate::util::choose(" You are not logged in. Login now?", &options)? {
403+
Some(0) => {},
404+
_ => bail!("Login is required to use chat"),
405+
}
406+
crate::cli::user::login_interactive(Default::default()).await?;
407+
} else {
408+
bail!(
409+
"You are not logged in, please log in with {}",
410+
format!("{CLI_BINARY_NAME} login",).bold()
411+
);
412+
}
402413
}
403414

404415
// Save credentials from the macOS keychain to sqlite.

crates/q_cli/src/util/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,12 @@ pub fn dialoguer_theme() -> ColorfulTheme {
290290
}
291291
}
292292

293+
pub async fn is_logged_in_check() -> bool {
294+
std::env::var("AMAZON_Q_SIGV4").is_ok_and(|v| !v.is_empty()) || fig_auth::is_logged_in().await
295+
}
296+
293297
pub async fn assert_logged_in() -> Result<(), Error> {
294-
if !(std::env::var("AMAZON_Q_SIGV4").is_ok_and(|v| !v.is_empty()) || fig_auth::is_logged_in().await) {
298+
if !is_logged_in_check().await {
295299
bail!(
296300
"You are not logged in, please log in with {}",
297301
format!("{CLI_BINARY_NAME} login",).bold()

0 commit comments

Comments
 (0)