Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(turborepo-auth): move logout function to crate #6057

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion crates/turborepo-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use reqwest::Url;
use serde::Deserialize;
use thiserror::Error;
use tokio::sync::OnceCell;
use tracing::error;
#[cfg(not(test))]
use tracing::warn;
use turborepo_api_client::APIClient;
use turborepo_ui::{start_spinner, BOLD, CYAN, UI};
use turborepo_ui::{start_spinner, BOLD, CYAN, GREY, UI};

const DEFAULT_HOST_NAME: &str = "127.0.0.1";
const DEFAULT_PORT: u16 = 9789;
Expand All @@ -30,6 +31,19 @@ pub enum Error {
LoginUrlCannotBeABase { value: String },
}

pub fn logout<F>(ui: &UI, mut set_token: F) -> Result<()>
where
F: FnMut() -> Result<()>,
{
if let Err(err) = set_token() {
error!("could not logout. Something went wrong: {}", err);
return Err(err.into());
}

println!("{}", ui.apply(GREY.apply_to(">>> Logged out")));
Ok(())
}

pub async fn login<F>(
api_client: APIClient,
ui: &UI,
Expand Down
16 changes: 8 additions & 8 deletions crates/turborepo-lib/src/commands/logout.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use anyhow::Result;
use tracing::error;
use turborepo_ui::GREY;
use turborepo_auth::logout as auth_logout;

use crate::commands::CommandBase;

pub fn logout(base: &mut CommandBase) -> Result<()> {
if let Err(err) = base.user_config_mut()?.set_token(None) {
error!("could not logout. Something went wrong: {}", err);
return Err(err.into());
}
let ui = base.ui;

println!("{}", base.ui.apply(GREY.apply_to(">>> Logged out")));
Ok(())
// Passing a closure here while we figure out how to make turborepo-auth
// crate manage its own configuration for the path to the token.
let set_token =
|| -> Result<(), anyhow::Error> { Ok(base.user_config_mut()?.set_token(None)?) };

auth_logout(&ui, set_token)
}
Loading