From 450ade4b5387658189f198e164f6cb0770eaaa38 Mon Sep 17 00:00:00 2001 From: Kr4ight Date: Mon, 6 Apr 2026 20:36:41 +0200 Subject: [PATCH] Fix: auth not refreshing on launch #15 --- src-tauri/src/launcher/auth.rs | 7 +++++-- src/App.tsx | 7 +++---- src/components/PlaySection.tsx | 22 ++++++++++++++++------ src/components/layout/AccountDropdown.tsx | 21 ++++++++++----------- src/components/layout/props.ts | 9 ++++----- src/lib/auth.ts | 3 ++- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src-tauri/src/launcher/auth.rs b/src-tauri/src/launcher/auth.rs index a1ac007..c6a2299 100644 --- a/src-tauri/src/launcher/auth.rs +++ b/src-tauri/src/launcher/auth.rs @@ -125,8 +125,11 @@ pub async fn auth_refresh(uuid: String) -> Result { } #[command] -pub fn auth_list() -> Result, String> { - Ok(load_accounts()) +pub fn auth_list() -> Result, String> { + Ok(load_accounts() + .iter() + .map(|account| (account.uuid.clone(), account.username.clone())) + .collect()) } #[command] diff --git a/src/App.tsx b/src/App.tsx index daa7827..6dfe2f3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,6 @@ import ModsSection from "./components/ModsSection"; import SettingsSection from "./components/SettingsSection"; import { versions } from "./lib/launcher"; import { GameVersion } from "./lib/types"; -import { MinecraftAccount } from "./lib/auth"; import { getVersion, installPaths, updateVersion } from "./lib/saturn"; import { getCurrentWindow } from "@tauri-apps/api/window"; import { listen } from "@tauri-apps/api/event"; @@ -26,8 +25,8 @@ export default function App() { const versionRef = useRef(null); const accountRef = useRef(null); - const [accounts, setAccounts] = useState([]); - const [activeAccount, setActiveAccount] = useState( + const [accounts, setAccounts] = useState<[string, string][]>([]); + const [activeAccount, setActiveAccount] = useState<[string, string] | null>( null, ); @@ -137,7 +136,7 @@ export default function App() {
{active === "play" && ( - + )} {active === "mods" && selectedVersion && ( diff --git a/src/components/PlaySection.tsx b/src/components/PlaySection.tsx index bc97ef6..55fab7d 100644 --- a/src/components/PlaySection.tsx +++ b/src/components/PlaySection.tsx @@ -1,19 +1,22 @@ import React, { useEffect, useState } from "react"; import { Play, Loader2 } from "lucide-react"; -// import { launchGame } from "../services/SaturnApi"; import Bg from "@/assets/bg.png"; import { listen } from "@tauri-apps/api/event"; import { GameVersion } from "@/lib/types"; import { launch } from "@/lib/launcher"; -import { MinecraftAccount } from "@/lib/auth"; +import { authGetValid } from "@/lib/auth"; import { cn } from "@/lib/utils"; +import { SetState } from "./layout/props"; interface PlaySectionProps { version: GameVersion | null; - account: MinecraftAccount | null; + activeAccount: [string, string] | null; + setActiveAccount: SetState<[string, string] | null>, + accounts: [string, string][], + setAccounts: SetState<[string, string][]>, } -const PlaySection: React.FC = ({ version, account }) => { +const PlaySection: React.FC = ({ version, activeAccount: account }) => { const [isLaunching, setIsLaunching] = useState(false); const [launchStatus, setLaunchStatus] = useState(""); const [progress, setProgress] = useState(0); @@ -39,6 +42,13 @@ const PlaySection: React.FC = ({ version, account }) => { }; }, []); + const handleLaunch = async () => { + if (version && account) { + const validAccount = await authGetValid(account[0]); + launch(version, validAccount); + } + } + return (
{/* Background Image */} @@ -54,12 +64,12 @@ const PlaySection: React.FC = ({ version, account }) => {
@@ -140,17 +139,17 @@ export default function AccountDropdown({ {/* Current account */} {activeAccount && ( )} {/* Other accounts */} {otherAccounts.map((acc) => ( switchAccount(acc)} /> ))} diff --git a/src/components/layout/props.ts b/src/components/layout/props.ts index c2aeed6..ff394cd 100644 --- a/src/components/layout/props.ts +++ b/src/components/layout/props.ts @@ -1,4 +1,3 @@ -import { MinecraftAccount } from "@/lib/auth"; import { GameVersion } from "@/lib/types"; export type SetState = React.Dispatch>; @@ -17,9 +16,9 @@ export interface Props { versionRef: React.RefObject; accountRef: React.RefObject; - accounts: MinecraftAccount[]; - setAccounts: SetState; + accounts: [string, string][]; + setAccounts: SetState<[string, string][]>; - activeAccount: MinecraftAccount | null; - setActiveAccount: SetState; + activeAccount: [string, string] | null; + setActiveAccount: SetState<[string, string] | null>; } diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 311c8ee..d17d8d9 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -33,8 +33,9 @@ export async function authRefresh(uuid: string): Promise { /** * Get all stored accounts + * Format [UUID, Username] */ -export async function authList(): Promise { +export async function authList(): Promise<[string, string][]> { return await invoke("auth_list"); }