Skip to content

Commit 892da7c

Browse files
committed
Added wipeUserSessions feature
1 parent fc70106 commit 892da7c

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/lib/code/api.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,25 @@ export function deleteUserAccount(deleteUserAccount: IDeleteUserAccount, complet
565565
})
566566
}
567567

568+
export function wipeUserSessions(completed: (wasSuccess: boolean) => void) {
569+
log("API Request: wipeUserSessions");
570+
axiosClient().post(`/api/v2/users/wipe/sessions`)
571+
.then((response) => {
572+
if (response?.status !== 200) {
573+
return Promise.reject(response);
574+
}
575+
576+
log(response?.status);
577+
log(response?.data);
578+
completed(true);
579+
})
580+
581+
.catch((error) => {
582+
console.error(`Failed to wipe user sessions Error: ${error}`)
583+
completed(false);
584+
})
585+
}
586+
568587
export function getPanelUserSettings(report: (wasSuccess: boolean, panelUserSettings: IPanelSettings) => void) {
569588
log("API Request: getPanelUserSettings");
570589
axiosClient().get(`/api/v2/users/current/settings`)
@@ -1025,7 +1044,6 @@ export function deleteSchedulerTask(serverId: string, taskId: string, completed:
10251044
})
10261045
}
10271046

1028-
10291047
export function getApiKeys(report: (apiKey: IApiKey[]) => void, completed: (wasSuccess: boolean) => void): void {
10301048
log("API Request: getApiKeys");
10311049
axiosClient().get(`/api/v2/keys`)

src/lib/pages/users/overview.svelte

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts">
2-
import { mdiAccountPlus, mdiCheck, mdiClose, mdiRefresh } from '@mdi/js';
3-
import { deletePanelUser, getPanelUsers } from '$lib/code/api';
2+
import { mdiAccountMultipleRemove, mdiAccountPlus, mdiCheck, mdiClose, mdiRefresh } from '@mdi/js';
3+
import { deletePanelUser, getPanelUsers, wipeUserSessions } from '$lib/code/api';
4+
import { onMount } from 'svelte';
45
import Icon from '$lib/components/elements/icon.svelte';
56
import { navigateToPage } from '$lib/code/routing';
67
import { Page, type IPanelUser } from '../../../types';
78
import Spinner from '$lib/components/elements/spinner.svelte';
89
import PageTitleBanner from '$lib/components/page/pageTitleBanner.svelte';
9-
import { onMount } from 'svelte';
1010
import Button from '$lib/components/elements/button.svelte';
1111
1212
let users: IPanelUser[] = [];
@@ -33,6 +33,21 @@
3333
load();
3434
}
3535
36+
function handleLogOutActiveUsersButton() {
37+
let allowedToLogout = confirm(`Are you sure you want to clear all active sessions? All users will need to login again, including you.`);
38+
if (!allowedToLogout) {
39+
return;
40+
}
41+
42+
wipeUserSessions((wasSuccess: boolean) => {
43+
if (wasSuccess) {
44+
confirm(`User sessions were cleared.`);
45+
} else {
46+
confirm(`Failed to wipe user sessions.`);
47+
}
48+
});
49+
}
50+
3651
function handleEditPanelUser(userId: string) {
3752
navigateToPage(Page.UsersEdit, userId);
3853
}
@@ -72,6 +87,15 @@
7287
<Icon data={mdiRefresh} size={5} class="" />
7388
</button>
7489
</div>
90+
<div class="self-center">
91+
<button
92+
type="button"
93+
on:click={handleLogOutActiveUsersButton}
94+
class="px-3 py-1.5 text-sm font-medium text-red-600 dark:text-red-500 bg-white border border-gray-200 rounded-lg focus:outline-none hover:bg-red-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:border-gray-600 dark:hover:text-white dark:hover:bg-red-700"
95+
>
96+
<Icon data={mdiAccountMultipleRemove} size={5} class="" />
97+
</button>
98+
</div>
7599
<div class="self-center">
76100
<Button icon={mdiAccountPlus} text={'Create User'} on:click={() => navigateToPage(Page.UsersCreate)} reactive={true} />
77101
</div>

0 commit comments

Comments
 (0)