Skip to content

Commit c626d36

Browse files
Cache session token for login in state
Fixes double login prompt when the Remember Me checkbox is unchecked on endpoint servers with multiple available versions
1 parent 160444b commit c626d36

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

app/page.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ export default function Home() {
5757
const [initialFetchDone, setInitialFetchDone] = useState(false);
5858
const [config, setConfig] = useState<Config | undefined>(undefined);
5959
const [servers, setServers] = useState<ServerEntry[]>([]);
60-
const [selectedIdx, setSelectedIdx] = useState<number>(-1);
61-
6260
const [versions, setVersions] = useState<VersionEntry[]>([]);
6361

62+
const [selectedIdx, setSelectedIdx] = useState<number>(-1);
63+
const [currentSession, setCurrentSession] = useState<LoginSession | undefined>(undefined);
64+
6465
const [alerts, setAlerts] = useState<Alert[]>([]);
6566
const [loadingTasks, setLoadingTasks] = useState<LoadingTask[]>([]);
6667

@@ -93,6 +94,7 @@ export default function Home() {
9394
} else {
9495
setSelectedIdx(-1);
9596
}
97+
setCurrentSession(undefined);
9698
};
9799

98100
const pushAlert = (variant: string, text: string, link?: string) => {
@@ -274,7 +276,7 @@ export default function Home() {
274276
await sleep(timeout * 1000);
275277
}
276278
stopLoading("launch");
277-
279+
setCurrentSession(undefined);
278280
if (config!.launcher.launch_behavior == "hide") {
279281
await getCurrentWindow().hide();
280282
}
@@ -349,24 +351,27 @@ export default function Home() {
349351
return;
350352
}
351353

352-
let session: LoginSession | undefined = undefined;
354+
let session: LoginSession | undefined = currentSession;
353355
let version: string | undefined = versionUuid ?? server.version;
354356
if (server.endpoint) {
355357
startLoading("configure_endpoint");
356358

357359
// authenticate before worrying about versions
358-
try {
359-
const loginSession: LoginSession = await invoke("get_session", {
360-
serverUuid: serverUuid,
361-
});
362-
session = loginSession;
363-
} catch {
364-
// If we can't get a session token for ANY REASON, we'll grab a new refresh token
365-
// by making the user log in again
366-
stopLoading("configure_endpoint");
367-
setShowLoginModal(true);
368-
setConnecting(false);
369-
return;
360+
if (!session) {
361+
try {
362+
const loginSession: LoginSession = await invoke("get_session", {
363+
serverUuid: serverUuid,
364+
});
365+
session = loginSession;
366+
setCurrentSession(loginSession);
367+
} catch {
368+
// If we can't get a session token for ANY REASON, we'll grab a new refresh token
369+
// by making the user log in again
370+
stopLoading("configure_endpoint");
371+
setShowLoginModal(true);
372+
setConnecting(false);
373+
return;
374+
}
370375
}
371376

372377
// check supported versions

0 commit comments

Comments
 (0)