Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

implement hotmart login command with session management and error handling

Tonho64c5c86a9c7c
diff --git a/src-tauri/src/commands/auth.rs b/src-tauri/src/commands/auth.rs
index e7480910..60687d16 100644
--- a/src-tauri/src/commands/auth.rs
+++ b/src-tauri/src/commands/auth.rs
@@ -1 +1,30 @@
-// TODO: Implement authentication Tauri commands (login, logout, check_session)
+use crate::platforms::hotmart::auth::authenticate;
+use crate::AppState;
+
+#[tauri::command]
+pub async fn hotmart_login(
+ state: tauri::State<'_, AppState>,
+ email: String,
+ password: String,
+) -> Result<String, String> {
+ tracing::info!("Comando hotmart_login invocado para {}", email);
+
+ match authenticate(&email, &password).await {
+ Ok(session) => {
+ let token = session.token.clone();
+ let mut guard = state.hotmart_session.lock().await;
+ *guard = Some(session);
+ tracing::info!("Sessão Hotmart salva no state global");
+
+ Ok(serde_json::to_string(&serde_json::json!({
+ "token": token,
+ "success": true
+ }))
+ .unwrap())
+ }
+ Err(e) => {
+ tracing::error!("Falha no login Hotmart: {}", e);
+ Err(format!("Falha no login: {}", e))
+ }
+ }
+}