YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: persist API key to SecretStore (db.sqlite), not store.bin
Louis Beaumontc2d248183dee
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs b/apps/screenpipe-app-tauri/src-tauri/src/recording.rsindex 3595a2969..aa099a667 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/recording.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/recording.rs@@ -422,22 +422,26 @@ pub async fn spawn_screenpipe(let recording_config = store.to_recording_config(data_dir);- // If an API key was auto-generated, persist it to the encrypted settings- // store so it survives restarts (replaces the old auth.json file approach).+ // Persist auto-generated API key to the SecretStore (encrypted in db.sqlite)+ // so it survives restarts and is discoverable by `screenpipe auth token`.if let Some(ref key) = recording_config.api_auth_key {- // Persist only if apiKey isn't already saved in settingsif store.recording.api_key.is_empty() {- if let Ok(tauri_store) = crate::store::get_store(&app, None) {- if let Some(mut settings_val) = tauri_store.get("settings") {- if let Some(obj) = settings_val.as_object_mut() {- obj.insert("apiKey".to_string(), serde_json::json!(key));- tauri_store.set("settings", settings_val);- let _ = tauri_store.save();- crate::store::reencrypt_store_file(&app);- tracing::info!("api auth: auto-generated key persisted to encrypted store");+ let key_clone = key.clone();+ let data_dir = data_dir.clone();+ tauri::async_runtime::spawn(async move {+ let db_path = data_dir.join("db.sqlite");+ let db_url = format!("sqlite:{}?mode=rwc", db_path.display());+ if let Ok(pool) = sqlx::SqlitePool::connect(&db_url).await {+ let secret_key = crate::secrets::get_or_create_key();+ if let Ok(store) = screenpipe_secrets::SecretStore::new(pool, secret_key).await {+ if let Err(e) = store.set("api_auth_key", key_clone.as_bytes()).await {+ tracing::warn!("failed to persist API key to secret store: {}", e);+ } else {+ tracing::info!("api auth: key persisted to encrypted secret store");+ }}}- }+ });}}diff --git a/crates/screenpipe-engine/src/cli/auth.rs b/crates/screenpipe-engine/src/cli/auth.rsindex ad7d6d0cd..9ec3bd9de 100644--- a/crates/screenpipe-engine/src/cli/auth.rs+++ b/crates/screenpipe-engine/src/cli/auth.rs@@ -31,25 +31,7 @@ async fn print_token() -> Result<()> {}}- // Priority 2: settings store (store.bin — used by desktop app)- let store_path = screenpipe_core::paths::default_screenpipe_data_dir().join("store.bin");- if store_path.exists() {- if let Ok(content) = std::fs::read_to_string(&store_path) {- if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(&content) {- let key = parsed- .pointer("/settings/apiKey")- .or_else(|| parsed.pointer("/state/settings/apiKey"))- .and_then(|v| v.as_str())- .filter(|s| !s.is_empty());- if let Some(key) = key {- println!("{}", key);- return Ok(());- }- }- }- }-- // Priority 3: secret store (db.sqlite — used by CLI)+ // Priority 2: SecretStore in db.sqlite (encrypted, keychain key)if let Ok(store) = open_secret_store().await {if let Ok(Some(bytes)) = store.get("api_auth_key").await {if let Ok(key) = String::from_utf8(bytes) {@@ -61,7 +43,7 @@ async fn print_token() -> Result<()> {}}- // Priority 4: legacy auth.json+ // Priority 3: legacy auth.json (for users upgrading)if let Some(home) = dirs::home_dir() {let auth_path = home.join(".screenpipe/auth.json");if let Ok(content) = std::fs::read_to_string(auth_path) {