session sign out

main
alex 2023-05-15 22:03:39 +02:00
parent d350b7feff
commit 8b2e631e3e
3 changed files with 29 additions and 11 deletions

View File

@ -98,7 +98,7 @@ export default function SideMenu({ setUserSession }) {
setUserSession();
window.location.href = "/";
fetch(Constants.API_ADDRESS + "/user/auth/logout", {
fetch(`${Constants.API_ADDRESS}/user/auth/logout`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",

View File

@ -28,7 +28,7 @@ export default function Login({ setUserSession }) {
return;
}
fetch(Constants.API_ADDRESS + "/user/auth/login", {
fetch(`${Constants.API_ADDRESS}/user/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({

View File

@ -1,6 +1,12 @@
import { Badge, Space, Table } from "antd";
import { Badge, Button, Space, Table } from "antd";
import { useContext } from "react";
import { FormatDatetime, WebSocketContext } from "../../utils";
import {
Constants,
FormatDatetime,
UseUserSession,
WebSocketContext,
} from "../../utils";
import { unstable_HistoryRouter } from "react-router-dom";
const columns = [
{
@ -27,11 +33,23 @@ const columns = [
title: "Action",
dataIndex: "action",
key: "action",
render: (_, record) => (
render: (_, record) => {
return (
<Space size="middle">
<a>Sign out</a>
<a
onClick={() => {
fetch(`${Constants.API_ADDRESS}/user/session/${record.key}`, {
method: "DELETE",
}).catch((err) => {
console.error(err);
});
}}
>
Sign out
</a>
</Space>
),
);
},
},
];
@ -45,9 +63,9 @@ export default function UserProfile() {
(a, b) => b.ConnectionStatus - a.ConnectionStatus
);
webSocketContext.User.Sessions.forEach((session, index) => {
webSocketContext.User.Sessions.forEach((session) => {
items.push({
key: "usersession" + index,
key: session.IdForDeletion,
userAgent: session.UserAgent,
connectionStatus:
session.ConnectionStatus === 0 ? (