aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/login.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2021-05-09 20:11:17 +0100
committerGitHub <noreply@github.com>2021-05-09 20:11:17 +0100
commite43e5ce74a85d87a625295b9b089a1b5b8e26fab (patch)
treeafbc97503090e320250440160a8ea9ee775fc170 /src/command/login.rs
parentFix resh importer crashing on end of file (#92) (diff)
downloadatuin-e43e5ce74a85d87a625295b9b089a1b5b8e26fab.zip
Add logout, only login if not already logged in (#91)
Also: - Ensures that a key is generated as soon as a user registers! - Ensures that "atuin key" will generate a key if needed, and doesn't double base64 encode data And a few other little fixes :) Resolves #85 Resolves #86
Diffstat (limited to 'src/command/login.rs')
-rw-r--r--src/command/login.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/command/login.rs b/src/command/login.rs
index eacb2105..9a144580 100644
--- a/src/command/login.rs
+++ b/src/command/login.rs
@@ -22,6 +22,16 @@ pub struct Cmd {
impl Cmd {
pub fn run(&self, settings: &Settings) -> Result<()> {
+ let session_path = atuin_common::utils::data_dir().join("session");
+
+ if session_path.exists() {
+ println!(
+ "You are already logged in! Please run 'atuin logout' if you wish to login again"
+ );
+
+ return Ok(());
+ }
+
let session = api_client::login(
settings.sync_address.as_str(),
self.username.as_str(),
@@ -34,7 +44,7 @@ impl Cmd {
let key_path = settings.key_path.as_str();
let mut file = File::create(key_path)?;
- file.write_all(&base64::decode(self.key.clone())?)?;
+ file.write_all(self.key.as_bytes())?;
println!("Logged in!");