Skip to content
13 changes: 5 additions & 8 deletions crates/chat-cli/src/auth/builder_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ use aws_smithy_runtime_api::client::identity::{
};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::region::Region;
use eyre::{
Result,
eyre,
};
use eyre::Result;
use time::OffsetDateTime;
use tracing::{
debug,
Expand Down Expand Up @@ -599,14 +596,14 @@ impl ResolveIdentity for BearerResolver {
}
}

pub async fn is_idc_user(database: &Database) -> Result<bool> {
pub async fn is_idc_user(database: &Database) -> bool {
if cfg!(test) {
return Ok(false);
return false;
}
if let Ok(Some(token)) = BuilderIdToken::load(database).await {
Ok(token.token_type() == TokenType::IamIdentityCenter)
token.token_type() == TokenType::IamIdentityCenter
} else {
Err(eyre!("No auth token found - is the user signed in?"))
false
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/chat-cli/src/cli/chat/cli/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ pub struct SubscribeArgs {

impl SubscribeArgs {
pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
if is_idc_user(&os.database)
.await
.map_err(|e| ChatError::Custom(e.to_string().into()))?
{
if is_idc_user(&os.database).await {
execute!(
session.stderr,
style::SetForegroundColor(Color::Yellow),
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ enum ActualSubscriptionStatus {
//
// Also, it is currently not possible to subscribe or re-subscribe via console, only IDE/CLI.
async fn get_subscription_status(os: &mut Os) -> Result<ActualSubscriptionStatus> {
if is_idc_user(&os.database).await? {
if is_idc_user(&os.database).await {
return Ok(ActualSubscriptionStatus::Active);
}

Expand Down
7 changes: 3 additions & 4 deletions crates/chat-cli/src/cli/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::auth::builder_id::{
BuilderIdToken,
PollCreateToken,
TokenType,
is_idc_user,
poll_create_token,
start_device_authorization,
};
Expand Down Expand Up @@ -338,10 +339,8 @@ pub enum LicenseType {
}

pub async fn profile(os: &mut Os) -> Result<ExitCode> {
if let Ok(Some(token)) = BuilderIdToken::load(&os.database).await {
if matches!(token.token_type(), TokenType::BuilderId) {
bail!("This command is only available for Pro users");
}
if !is_idc_user(&os.database).await {
bail!("This command is only available for IAM Identity Center users");
}

select_profile_interactive(os, false).await?;
Expand Down
15 changes: 10 additions & 5 deletions crates/q_cli/src/cli/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ impl RootUserSubcommand {
Self::Profile => {
assert_logged_in().await?;

if let Ok(Some(token)) = fig_auth::builder_id_token().await {
if matches!(token.token_type(), TokenType::IamIdentityCenter) {
select_profile_interactive(false).await?;
}
let is_idc = fig_auth::builder_id_token()
.await
.ok()
.flatten()
.is_some_and(|token| matches!(token.token_type(), TokenType::IamIdentityCenter));

if !is_idc {
bail!("This command is only available for IAM Identity Center users");
}

bail!("This command is only available for IAM Identity Center users");
select_profile_interactive(false).await?;
Ok(ExitCode::SUCCESS)
},
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/dashboard-app/src/pages/settings/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default function Page() {
const [profiles, setProfiles] = useState<Profile[] | undefined>(undefined);

useEffect(() => {
if (auth.authKind !== "IamIdentityCenter") {
return;
}

Profile.listAvailableProfiles()
.then(async (res) => {
setProfiles(
Expand All @@ -35,7 +39,7 @@ export default function Page() {
.catch((err) => {
console.error(err);
});
}, []);
}, [auth.authKind]);

useEffect(() => {
State.get("api.codewhisperer.profile").then((profile) => {
Expand Down
Loading