Disable authentication in read-only mode

Tell the user how to enable experimental mode where authentication
works.
This commit is contained in:
Rūdolfs Ošiņš
2024-03-14 16:57:36 +01:00
parent d7521a4608
commit a1db517346
2 changed files with 27 additions and 11 deletions
+7 -9
View File
@@ -64,6 +64,9 @@ export async function authenticate(params: {
signature: string;
publicKey: string;
}): Promise<boolean> {
if (!get(experimental)) {
return false;
}
stateMutex.cancel();
return stateMutex.runExclusive(async () => {
try {
@@ -150,15 +153,6 @@ async function checkState() {
scope: config?.scope,
};
// Return quickly and avoid additional fetches
// if experimental settings aren't updated
if (!get(experimental)) {
update({
state: "running",
node,
});
}
if (httpdState && httpdState.state !== "stopped") {
httpdState.node = node;
}
@@ -216,6 +210,10 @@ function pollSession() {
}
export async function initialize() {
if (!get(experimental)) {
return;
}
// Sync session state changes with other open tabs and windows.
addEventListener("storage", event => {
if (
+20 -2
View File
@@ -3,14 +3,16 @@
import { onMount } from "svelte";
import * as httpd from "@app/lib/httpd";
import * as modal from "@app/lib/modal";
import * as router from "@app/lib/router";
import * as httpd from "@app/lib/httpd";
import { experimental } from "@app/lib/appearance";
import AppLayout from "@app/App/AppLayout.svelte";
import Loading from "@app/components/Loading.svelte";
import AuthenticationErrorModal from "@app/modals/AuthenticationErrorModal.svelte";
import ErrorModal from "@app/modals/ErrorModal.svelte";
export let activeRoute: SessionRoute;
@@ -21,12 +23,28 @@
}
const isAuthenticated = await httpd.authenticate(activeRoute.params);
if (!isAuthenticated) {
if (!isAuthenticated && !$experimental) {
modal.show({
component: ErrorModal,
props: {
title: "Authentication failed",
subtitle: [
"Authentication only works in experimental mode.",
"Go to Settings, set experimental mode to On and try again.",
],
error: {
message: "Can't authenticate in read-only mode.",
stack: undefined,
},
},
});
} else if (!isAuthenticated) {
modal.show({
component: AuthenticationErrorModal,
props: {},
});
}
void router.navigateToUrl(
"push",
new URL(activeRoute.params.path || "", window.location.origin),