Skip to content

Commit 92a4410

Browse files
committed
lastpass: check if we're logged in
1 parent e4a70e4 commit 92a4410

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/provider/lastpass.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,32 @@ impl LastPassProvider {
118118
}
119119

120120
fn sync_if_needed(&self) -> Result<()> {
121+
// Check if we're logged in first
122+
if !self.check_login_status()? {
123+
return Err(SecretSpecError::ProviderOperationFailed(
124+
"LastPass authentication required. Please run 'lpass login <your-email>' first."
125+
.to_string(),
126+
));
127+
}
128+
121129
if self.config.sync_on_access {
122130
self.execute_lpass_command(&["sync"])?;
123131
}
124132
Ok(())
125133
}
134+
135+
fn check_login_status(&self) -> Result<bool> {
136+
match self.execute_lpass_command(&["status"]) {
137+
Ok(output) => Ok(!output.contains("Not logged in")),
138+
Err(SecretSpecError::ProviderOperationFailed(msg))
139+
if msg.contains("Not logged in")
140+
|| msg.contains("LastPass authentication required") =>
141+
{
142+
Ok(false)
143+
}
144+
Err(e) => Err(e),
145+
}
146+
}
126147
}
127148

128149
impl Provider for LastPassProvider {

0 commit comments

Comments
 (0)