Better pass handling through links
This commit is contained in:
parent
56ae4460b0
commit
e320f15ff9
3 changed files with 35 additions and 3 deletions
|
|
@ -16,6 +16,16 @@ export interface ClientSettings {
|
|||
|
||||
const TOKEN_KEY = "spacegaem_proto_token";
|
||||
const SETTINGS_KEY = "spacegaem_proto_settings";
|
||||
const SERVER_JOIN_KEY = "spacegaem_server_join_ok";
|
||||
|
||||
export function getServerJoinOk(): boolean {
|
||||
return sessionStorage.getItem(SERVER_JOIN_KEY) === "1";
|
||||
}
|
||||
|
||||
export function setServerJoinOk(ok: boolean): void {
|
||||
if (ok) sessionStorage.setItem(SERVER_JOIN_KEY, "1");
|
||||
else sessionStorage.removeItem(SERVER_JOIN_KEY);
|
||||
}
|
||||
|
||||
export function getToken(): string | null {
|
||||
return localStorage.getItem(TOKEN_KEY);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
// Renders the animated 3D solar system main menu, settings dialog, and quick-join entry.
|
||||
// Again, self explanatory
|
||||
|
||||
import { api, getSettings, saveSettings } from "../api.js";
|
||||
import {
|
||||
api,
|
||||
getServerJoinOk,
|
||||
getSettings,
|
||||
saveSettings,
|
||||
setServerJoinOk,
|
||||
} from "../api.js";
|
||||
import { navigate } from "../router.js";
|
||||
import { refreshMe, refreshWorld, startEvents } from "../session.js";
|
||||
import { state } from "../state.js";
|
||||
|
|
@ -211,7 +217,7 @@ function proceedAfterJoin(): void {
|
|||
}
|
||||
|
||||
function handleJoinClick(): void {
|
||||
if (!state.serverInfo?.serverPasswordRequired) {
|
||||
if (!state.serverInfo?.serverPasswordRequired || getServerJoinOk()) {
|
||||
proceedAfterJoin();
|
||||
return;
|
||||
}
|
||||
|
|
@ -241,6 +247,7 @@ function handleJoinClick(): void {
|
|||
errLine.textContent = "";
|
||||
try {
|
||||
await api.post("/api/join", { password: pwdInput.value }, false);
|
||||
setServerJoinOk(true);
|
||||
proceedAfterJoin();
|
||||
} catch (err) {
|
||||
errLine.textContent = (err as Error).message;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue