Better pass handling through links

This commit is contained in:
tyuXX 2026-11-15 14:44:30 +03:00
parent 56ae4460b0
commit e320f15ff9
3 changed files with 35 additions and 3 deletions

View file

@ -1,5 +1,5 @@
// Literally everything (pls help me my autocorrect is trying to insult me how does this even work)
import { getSettings, saveSettings } from "./api.js";
import { api, getSettings, saveSettings, setServerJoinOk } from "./api.js";
import { navigate, registerScreenRenderers } from "./router.js";
import {
loadCatalogs,
@ -128,6 +128,21 @@ async function boot(): Promise<void> {
} catch (err) {
toast(`Failed to load mission catalogs: ${(err as Error).message}`, "err");
}
const passParam = new URLSearchParams(window.location.search).get("pass");
if (passParam) {
const url = new URL(window.location.href);
url.searchParams.delete("pass");
window.history.replaceState(null, "", url.toString());
if (state.serverInfo?.serverPasswordRequired) {
try {
await api.post("/api/join", { password: passParam }, false);
setServerJoinOk(true);
toast("Server access granted via link.", "ok");
} catch {
toast("Server password in link was rejected.", "err");
}
}
}
await refreshMe();
if (state.agency) {
await refreshWorld();