Added logout all sessions to user session tab (#2696)

This commit is contained in:
Erik Jan de Wit 2022-05-27 11:27:30 +02:00 committed by GitHub
parent 1fa1e0dc46
commit 422c271da3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -22,6 +22,7 @@
"signOutAllActiveSessions": "Sign out all active sessions",
"signOutAllActiveSessionsQuestion": "Sign out all active sessions?",
"setToNow": "Set to now",
"logoutAllSessions": "Logout all sessions",
"logoutAllDescription": "If you sign out all active sessions, active subjects in this realm will be signed out.",
"logoutAllSessionsError": "Error! Failed to log out of all sessions: {{error}}.",
"setToNowError": "Error! Failed to set notBefore to current date and time.",

View file

@ -1,5 +1,11 @@
import type UserSessionRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userSessionRepresentation";
import { List, ListItem, ListVariant } from "@patternfly/react-core";
import {
Button,
List,
ListItem,
ListVariant,
ToolbarItem,
} from "@patternfly/react-core";
import { CubesIcon } from "@patternfly/react-icons";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
@ -24,12 +30,14 @@ export type SessionsTableProps = {
loader: LoaderFunction<UserSessionRepresentation>;
hiddenColumns?: ColumnName[];
emptyInstructions?: string;
logoutUser?: string;
};
export default function SessionsTable({
loader,
hiddenColumns = [],
emptyInstructions,
logoutUser,
}: SessionsTableProps) {
const { realm } = useRealm();
const { whoAmI } = useWhoAmI();
@ -106,6 +114,20 @@ export default function SessionsTable({
loader={loader}
ariaLabelKey="sessions:title"
searchPlaceholderKey="sessions:searchForSession"
toolbarItem={
logoutUser && (
<ToolbarItem>
<Button
onClick={async () => {
await adminClient.users.logout({ id: logoutUser });
refresh();
}}
>
{t("logoutAllSessions")}
</Button>
</ToolbarItem>
)
}
columns={columns}
actions={[
{

View file

@ -22,6 +22,7 @@ export const UserSessions = () => {
loader={loader}
hiddenColumns={["username"]}
emptyInstructions={t("noSessionsForUser")}
logoutUser={id}
/>
</PageSection>
);