Skip to content

Commit

Permalink
flowctl: Fix running unauthenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
jshearer committed Oct 4, 2024
1 parent 063f286 commit d55ecee
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions crates/flowctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,24 @@ impl Cli {
let mut config = config::Config::load(&self.profile)?;
let output = self.output.clone();

let client: flow_client::Client = config.build_anon_client();

let (access, refresh) =
refresh_authorizations(&client, config.user_access_token, config.user_refresh_token)
.await?;

// Make sure to store refreshed tokens back in Config so they get written back to disk
config.user_access_token = Some(access.to_owned());
config.user_refresh_token = Some(refresh.to_owned());

let client = client.with_creds(Some(access), Some(refresh));
let anon_client: flow_client::Client = config.build_anon_client();

let client = if let Ok((access, refresh)) = refresh_authorizations(
&anon_client,
config.user_access_token.to_owned(),
config.user_refresh_token.to_owned(),
)
.await
{
// Make sure to store refreshed tokens back in Config so they get written back to disk
config.user_access_token = Some(access.to_owned());
config.user_refresh_token = Some(refresh.to_owned());

anon_client.with_creds(Some(access), Some(refresh))
} else {
tracing::warn!("You are not authenticated. Run `auth login` to login to Flow.");
anon_client
};

let mut context = CliContext {
client,
Expand Down

0 comments on commit d55ecee

Please sign in to comment.