diff --git a/Cargo.lock b/Cargo.lock index cddf8da31e4..e43fa8a85cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7584,9 +7584,9 @@ dependencies = [ [[package]] name = "tauri-plugin-http" -version = "2.2.0" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e62a9bde54d6a0218b63f5a248f02056ad4316ba6ad81dfb9e4f73715df5deb1" +checksum = "696ef548befeee6c6c17b80ef73e7c41205b6c2204e87ef78ccc231212389a5c" dependencies = [ "data-url", "http", diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 8a598bec870..ff39e3669c1 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -41,7 +41,7 @@ "@tauri-apps/plugin-deep-link": "^2.2.0", "@tauri-apps/plugin-dialog": "2.0.1", "@tauri-apps/plugin-fs": "2.2.0", - "@tauri-apps/plugin-http": "^2.0.1", + "@tauri-apps/plugin-http": "^2.4.4", "@tauri-apps/plugin-notification": "2.0.0", "@tauri-apps/plugin-opener": "^2.2.6", "@tauri-apps/plugin-os": "2.0.0", @@ -64,7 +64,8 @@ "unplugin-icons": "^0.19.2", "uuid": "^9.0.1", "vinxi": "^0.5.6", - "webcodecs": "^0.1.0" + "webcodecs": "^0.1.0", + "zod": "^3.24.2" }, "devDependencies": { "@fontsource/geist-sans": "^5.0.3", diff --git a/apps/desktop/src-tauri/src/auth.rs b/apps/desktop/src-tauri/src/auth.rs index 40984ce823f..40695416144 100644 --- a/apps/desktop/src-tauri/src/auth.rs +++ b/apps/desktop/src-tauri/src/auth.rs @@ -10,13 +10,19 @@ use crate::web_api; #[derive(Serialize, Deserialize, Type, Debug)] pub struct AuthStore { - pub token: String, + pub secret: AuthSecret, pub user_id: Option, - pub expires: i32, pub plan: Option, pub intercom_hash: Option, } +#[derive(Serialize, Deserialize, Type, Debug)] +#[serde(untagged)] +pub enum AuthSecret { + ApiKey { api_key: String }, + Session { token: String, expires: i32 }, +} + #[derive(Serialize, Deserialize, Type, Debug)] pub struct Plan { pub upgraded: bool, @@ -108,12 +114,6 @@ impl AuthStore { return Err("Store not found".to_string()); }; - let value = value.map(|mut auth| { - // Set expiration to 100 years in the future - auth.expires = (chrono::Utc::now() + chrono::Duration::days(36500)).timestamp() as i32; - auth - }); - store.set("auth", json!(value)); store.save().map_err(|e| e.to_string()) } diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 391e9f6afbf..d199d89d3a2 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -1715,7 +1715,7 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { } } - let Ok(Some(mut auth)) = AuthStore::get(&app) else { + let Ok(Some(auth)) = AuthStore::get(&app) else { println!("No auth found, clearing auth store"); AuthStore::set(&app, None).map_err(|e| e.to_string())?; return Ok(false); @@ -1732,7 +1732,6 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { "Fetching plan for user {}", auth.user_id.as_deref().unwrap_or("unknown") ); - let plan_url = app.make_app_url("/api/desktop/plan"); let response = app .authed_api_request("/api/desktop/plan", |client, url| client.get(url)) .await @@ -1759,9 +1758,8 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result { .unwrap_or(false); println!("Pro status: {}", is_pro); let updated_auth = AuthStore { - token: auth.token, + secret: auth.secret, user_id: auth.user_id, - expires: auth.expires, intercom_hash: auth.intercom_hash, plan: Some(Plan { upgraded: is_pro, diff --git a/apps/desktop/src-tauri/src/web_api.rs b/apps/desktop/src-tauri/src/web_api.rs index c8478523df2..9afb4ec38ad 100644 --- a/apps/desktop/src-tauri/src/web_api.rs +++ b/apps/desktop/src-tauri/src/web_api.rs @@ -3,8 +3,8 @@ use tauri::{Emitter, Manager, Runtime}; use tauri_specta::Event; use crate::{ - auth::{AuthStore, AuthenticationInvalid}, - ArcLock, MutableState, + auth::{AuthSecret, AuthStore, AuthenticationInvalid}, + ArcLock, }; async fn do_authed_request( @@ -14,7 +14,16 @@ async fn do_authed_request( ) -> Result { let client = reqwest::Client::new(); - let mut req = build(client, url).header("Authorization", format!("Bearer {}", auth.token)); + let mut req = build(client, url).header( + "Authorization", + format!( + "Bearer {}", + match &auth.secret { + AuthSecret::ApiKey { api_key } => api_key, + AuthSecret::Session { token, .. } => token, + } + ), + ); if let Some(s) = std::option_env!("VITE_VERCEL_AUTOMATION_BYPASS_SECRET") { req = req.header("x-vercel-protection-bypass", s); diff --git a/apps/desktop/src/components/SignInButton.tsx b/apps/desktop/src/components/SignInButton.tsx index 3ef0ab41eb5..755f724ca6c 100644 --- a/apps/desktop/src/components/SignInButton.tsx +++ b/apps/desktop/src/components/SignInButton.tsx @@ -4,6 +4,7 @@ import { invoke } from "@tauri-apps/api/core"; import { listen } from "@tauri-apps/api/event"; import { onOpenUrl } from "@tauri-apps/plugin-deep-link"; import * as shell from "@tauri-apps/plugin-shell"; +import { z } from "zod"; import { getCurrentWindow } from "@tauri-apps/api/window"; import { ComponentProps } from "solid-js"; @@ -12,27 +13,12 @@ import { identifyUser, trackEvent } from "~/utils/analytics"; import { clientEnv } from "~/utils/env"; import { commands } from "~/utils/tauri"; import callbackTemplate from "./callback.template"; +import { createSignInMutation } from "~/utils/auth"; export function SignInButton( props: Omit, "onClick"> ) { - const signIn = createMutation(() => ({ - mutationFn: async (abort: AbortController) => { - const platform = import.meta.env.DEV ? "web" : "desktop"; - - let session; - - if (platform === "web") - session = await createLocalServerSession(abort.signal); - else session = await createDeepLinkSession(abort.signal); - - await shell.open(session.url.toString()); - - await processAuthData(await session.complete()); - - getCurrentWindow().setFocus(); - }, - })); + const signIn = createSignInMutation(); return ( - - - Previous Recordings - - } - > + getCurrentWindow().hide(); + }} + class="flex items-center justify-center w-5 h-5 -ml-[1.5px]" + > + + + + Previous Recordings}> - + type="button" + onClick={async () => { + await commands.showWindow({ Settings: { page: "recordings" } }); + getCurrentWindow().hide(); + }} + class="flex justify-center items-center w-5 h-5" + > + + + @@ -794,7 +782,6 @@ function MicrophoneSelect(props: { const [dbs, setDbs] = createSignal(); const [isInitialized, setIsInitialized] = createSignal(false); - const requestPermission = useRequestPermission(); const permissionGranted = () => @@ -1036,7 +1023,7 @@ function TargetSelectInfoPill(props: { ? "On" : "Off"} -); + ); } function InfoPill( @@ -1112,10 +1099,7 @@ function ChangelogButton() { }); return ( - +