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
This commit is contained in:
Zef Hemel
2025-03-28 13:45:39 +01:00
parent 2787c40ebe
commit 1703020a8a
5 changed files with 17 additions and 5 deletions
+6 -2
View File
@@ -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": () => {
+2 -2
View File
@@ -75,6 +75,6 @@ export function getConfig<T = any>(
return syscall("system.getConfig", key, defaultValue);
}
export function wipeClient(): Promise<void> {
return syscall("system.wipeClient");
export function wipeClient(logout = false): Promise<void> {
return syscall("system.wipeClient", logout);
}
+5
View File
@@ -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:
+4
View File
@@ -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();
}
-1
View File
@@ -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));