From 1703020a8abbddee206bb0cecdb72ee0a87bfc38 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 28 Mar 2025 13:45:39 +0100 Subject: [PATCH] feat: Add logout option to client wipe functionality - Add optional logout parameter to system.wipeClient - Add new 'Clear Local Storage & Logout' command - Update API to support logout parameter - Clean up server code comments --- common/syscalls/system.ts | 8 ++++++-- plug-api/syscalls/system.ts | 4 ++-- plugs/editor/editor.plug.yaml | 5 +++++ plugs/editor/system.ts | 4 ++++ server/http_server.ts | 1 - 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/common/syscalls/system.ts b/common/syscalls/system.ts index 2da6ab7c..2aeffb2b 100644 --- a/common/syscalls/system.ts +++ b/common/syscalls/system.ts @@ -99,7 +99,7 @@ export function systemSyscalls( } await client.loadCustomStyles(); }, - "system.wipeClient": async () => { + "system.wipeClient": async (_ctx, logout = false) => { // Two tracks: // 1. Service worker unregister // 2. IndexedDB cleaning @@ -157,7 +157,11 @@ export function systemSyscalls( } await client.ds.batchDelete(allKeys); } - alert("Client wiped, feel free to navigate elsewhere"); + if (logout) { + location.href = "/.logout"; + } else { + alert("Client wiped, feel free to navigate elsewhere"); + } }, // DEPRECATED "system.getEnv": () => { diff --git a/plug-api/syscalls/system.ts b/plug-api/syscalls/system.ts index 5c79c433..8c5f7d2c 100644 --- a/plug-api/syscalls/system.ts +++ b/plug-api/syscalls/system.ts @@ -75,6 +75,6 @@ export function getConfig( return syscall("system.getConfig", key, defaultValue); } -export function wipeClient(): Promise { - return syscall("system.wipeClient"); +export function wipeClient(logout = false): Promise { + return syscall("system.wipeClient", logout); } diff --git a/plugs/editor/editor.plug.yaml b/plugs/editor/editor.plug.yaml index ee7055bb..30039963 100644 --- a/plugs/editor/editor.plug.yaml +++ b/plugs/editor/editor.plug.yaml @@ -323,6 +323,11 @@ functions: command: name: "System: Wipe Client" + wipeAndLogoutCommand: + path: ./system.ts:wipeAndLogoutCommand + command: + name: "Clear Local Storage & Logout" + versionCommand: path: ./help.ts:versionCommand command: diff --git a/plugs/editor/system.ts b/plugs/editor/system.ts index a47339fb..fca22872 100644 --- a/plugs/editor/system.ts +++ b/plugs/editor/system.ts @@ -26,6 +26,10 @@ export async function wipeClientCommand() { await system.wipeClient(); } +export async function wipeAndLogoutCommand() { + await system.wipeClient(true); +} + export async function reloadUICommand() { await editor.reloadUI(); } diff --git a/server/http_server.ts b/server/http_server.ts index d1f80674..58f7a6a3 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -238,7 +238,6 @@ export class HttpServer { ) : new LockoutTimer(0, 0); // disabled - // TODO: This should probably be a POST request this.app.get("/.logout", (c) => { const url = new URL(c.req.url); deleteCookie(c, authCookieName(url.host));