Browse Source

fix: real time auth

stage
Vitalik 3 weeks ago
parent
commit
cf6951a4c5
  1. 125
      package-lock.json
  2. 2
      package.json
  3. 42
      src/containers/Logs/configs/columns.config.tsx
  4. 13
      src/services/system/jwt.service.ts
  5. 20
      src/services/system/real-time.service.ts
  6. 1869
      yarn.lock

125
package-lock.json generated

@ -45,6 +45,7 @@
"chalk": "^2.4.2", "chalk": "^2.4.2",
"chart.js": "^2.7.3", "chart.js": "^2.7.3",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"core-js": "^3.38.1",
"css-loader": "4.3.0", "css-loader": "4.3.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"dotenv-expand": "5.1.0", "dotenv-expand": "5.1.0",
@ -74,6 +75,7 @@
"jest-watch-typeahead": "0.6.1", "jest-watch-typeahead": "0.6.1",
"jet-tools": "^1.3.0", "jet-tools": "^1.3.0",
"js-base64": "^3.7.6", "js-base64": "^3.7.6",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.9.51", "libphonenumber-js": "^1.9.51",
"linkify-plugin-mention": "^3.0.4", "linkify-plugin-mention": "^3.0.4",
"linkify-react": "^3.0.4", "linkify-react": "^3.0.4",
@ -179,7 +181,7 @@
"webpack-manifest-plugin": "2.2.0", "webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "5.1.4", "workbox-webpack-plugin": "5.1.4",
"xlsx": "^0.15.5", "xlsx": "^0.15.5",
"zustand": "^4.5.2" "zustand": "^4.5.4"
}, },
"devDependencies": { "devDependencies": {
"@babel/helper-call-delegate": "^7.12.13", "@babel/helper-call-delegate": "^7.12.13",
@ -9011,10 +9013,15 @@
} }
}, },
"node_modules/core-js": { "node_modules/core-js": {
"version": "1.2.7", "version": "3.38.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz",
"integrity": "sha512-ZiPp9pZlgxpWRu0M+YWbm6+aQ84XEfH1JRXvfOc/fILWI0VKhLC2LX13X1NYq4fULzLMq7Hfh43CSo2/aIaUPA==", "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==",
"deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js." "hasInstallScript": true,
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
}, },
"node_modules/core-js-compat": { "node_modules/core-js-compat": {
"version": "3.36.0", "version": "3.36.0",
@ -12697,6 +12704,13 @@
"ua-parser-js": "^0.7.30" "ua-parser-js": "^0.7.30"
} }
}, },
"node_modules/fbjs/node_modules/core-js": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha512-ZiPp9pZlgxpWRu0M+YWbm6+aQ84XEfH1JRXvfOc/fILWI0VKhLC2LX13X1NYq4fULzLMq7Hfh43CSo2/aIaUPA==",
"deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.",
"license": "MIT"
},
"node_modules/figgy-pudding": { "node_modules/figgy-pudding": {
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz",
@ -17689,6 +17703,12 @@
"pako": "~0.2.5" "pako": "~0.2.5"
} }
}, },
"node_modules/jwt-decode": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz",
"integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==",
"license": "MIT"
},
"node_modules/keyv": { "node_modules/keyv": {
"version": "4.5.4", "version": "4.5.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
@ -22430,16 +22450,6 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/react-app-polyfill/node_modules/core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw==",
"hasInstallScript": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/react-app-polyfill/node_modules/promise": { "node_modules/react-app-polyfill/node_modules/promise": {
"version": "8.3.0", "version": "8.3.0",
"resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz", "resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz",
@ -24083,16 +24093,6 @@
"decimal.js-light": "^2.4.1" "decimal.js-light": "^2.4.1"
} }
}, },
"node_modules/recharts/node_modules/core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw==",
"hasInstallScript": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/recharts/node_modules/d3-array": { "node_modules/recharts/node_modules/d3-array": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz", "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz",
@ -25813,16 +25813,6 @@
"tslib": "^1.10.0" "tslib": "^1.10.0"
} }
}, },
"node_modules/smooth-scrollbar/node_modules/core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw==",
"hasInstallScript": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/core-js"
}
},
"node_modules/snapdragon": { "node_modules/snapdragon": {
"version": "0.8.2", "version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
@ -28236,9 +28226,10 @@
} }
}, },
"node_modules/use-sync-external-store": { "node_modules/use-sync-external-store": {
"version": "1.2.0", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==",
"license": "MIT",
"peerDependencies": { "peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
} }
@ -30546,11 +30537,12 @@
} }
}, },
"node_modules/zustand": { "node_modules/zustand": {
"version": "4.5.2", "version": "4.5.5",
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz", "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.5.tgz",
"integrity": "sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==", "integrity": "sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==",
"license": "MIT",
"dependencies": { "dependencies": {
"use-sync-external-store": "1.2.0" "use-sync-external-store": "1.2.2"
}, },
"engines": { "engines": {
"node": ">=12.7.0" "node": ">=12.7.0"
@ -37242,9 +37234,9 @@
} }
}, },
"core-js": { "core-js": {
"version": "1.2.7", "version": "3.38.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz",
"integrity": "sha512-ZiPp9pZlgxpWRu0M+YWbm6+aQ84XEfH1JRXvfOc/fILWI0VKhLC2LX13X1NYq4fULzLMq7Hfh43CSo2/aIaUPA==" "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw=="
}, },
"core-js-compat": { "core-js-compat": {
"version": "3.36.0", "version": "3.36.0",
@ -40117,6 +40109,13 @@
"promise": "^7.1.1", "promise": "^7.1.1",
"setimmediate": "^1.0.5", "setimmediate": "^1.0.5",
"ua-parser-js": "^0.7.30" "ua-parser-js": "^0.7.30"
},
"dependencies": {
"core-js": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
"integrity": "sha512-ZiPp9pZlgxpWRu0M+YWbm6+aQ84XEfH1JRXvfOc/fILWI0VKhLC2LX13X1NYq4fULzLMq7Hfh43CSo2/aIaUPA=="
}
} }
}, },
"figgy-pudding": { "figgy-pudding": {
@ -43894,6 +43893,11 @@
"pako": "~0.2.5" "pako": "~0.2.5"
} }
}, },
"jwt-decode": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz",
"integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A=="
},
"keyv": { "keyv": {
"version": "4.5.4", "version": "4.5.4",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
@ -47727,11 +47731,6 @@
"whatwg-fetch": "^3.4.1" "whatwg-fetch": "^3.4.1"
}, },
"dependencies": { "dependencies": {
"core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw=="
},
"promise": { "promise": {
"version": "8.3.0", "version": "8.3.0",
"resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz", "resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz",
@ -49020,11 +49019,6 @@
"reduce-css-calc": "^1.3.0" "reduce-css-calc": "^1.3.0"
}, },
"dependencies": { "dependencies": {
"core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw=="
},
"d3-array": { "d3-array": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz", "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz",
@ -50404,13 +50398,6 @@
"requires": { "requires": {
"core-js": "^3.6.4", "core-js": "^3.6.4",
"tslib": "^1.10.0" "tslib": "^1.10.0"
},
"dependencies": {
"core-js": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz",
"integrity": "sha512-mt7+TUBbTFg5+GngsAxeKBTl5/VS0guFeJacYge9OmHb+m058UwwIm41SE9T4Den7ClatV57B6TYTuJ0CX1MAw=="
}
} }
}, },
"snapdragon": { "snapdragon": {
@ -52276,9 +52263,9 @@
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==" "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ=="
}, },
"use-sync-external-store": { "use-sync-external-store": {
"version": "1.2.0", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==",
"requires": {} "requires": {}
}, },
"util": { "util": {
@ -54150,11 +54137,11 @@
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
}, },
"zustand": { "zustand": {
"version": "4.5.2", "version": "4.5.5",
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz", "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.5.tgz",
"integrity": "sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==", "integrity": "sha512-+0PALYNJNgK6hldkgDq2vLrw5f6g/jCInz52n9RTpropGgeAf/ioFUCdtsjCqu4gNhW9D01rUQBROoRjdzyn2Q==",
"requires": { "requires": {
"use-sync-external-store": "1.2.0" "use-sync-external-store": "1.2.2"
} }
} }
} }

2
package.json

@ -40,6 +40,7 @@
"chalk": "^2.4.2", "chalk": "^2.4.2",
"chart.js": "^2.7.3", "chart.js": "^2.7.3",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"core-js": "^3.38.1",
"css-loader": "4.3.0", "css-loader": "4.3.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"dotenv-expand": "5.1.0", "dotenv-expand": "5.1.0",
@ -69,6 +70,7 @@
"jest-watch-typeahead": "0.6.1", "jest-watch-typeahead": "0.6.1",
"jet-tools": "^1.3.0", "jet-tools": "^1.3.0",
"js-base64": "^3.7.6", "js-base64": "^3.7.6",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.9.51", "libphonenumber-js": "^1.9.51",
"linkify-plugin-mention": "^3.0.4", "linkify-plugin-mention": "^3.0.4",
"linkify-react": "^3.0.4", "linkify-react": "^3.0.4",

42
src/containers/Logs/configs/columns.config.tsx

@ -1,9 +1,15 @@
import React from "react"; import React from "react";
import { createFullName, EUserStatus, IPListType } from "@/shared"; import {
createFullName,
EUserStatus,
IPListType,
notification,
} from "@/shared";
import moment from "moment"; import moment from "moment";
import { voidColumn } from "@/components/TableGrid/configs/void-row.config"; import { voidColumn } from "@/components/TableGrid/configs/void-row.config";
import _ from "lodash"; import _ from "lodash";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { Button, Tooltip } from "antd";
export const columnsConfig: any = (page = 0) => [ export const columnsConfig: any = (page = 0) => [
voidColumn, voidColumn,
@ -74,7 +80,39 @@ export const columnsConfig: any = (page = 0) => [
formatter: ({ row }) => { formatter: ({ row }) => {
if (_.isEmpty(row)) return ""; if (_.isEmpty(row)) return "";
if (!row.ip) return <div className="ellipsis">{"Невідомо"}</div>; if (!row.ip) return <div className="ellipsis">{"Невідомо"}</div>;
return <div className="ellipsis">{row.ip?.replace("::ffff:", "")}</div>; return (
<div className="ellipsis">
{row.ip?.replace("::ffff:", "").split("///")[0]}
</div>
);
},
},
{
name: "Fingreprint",
key: "fingreprint",
minWidth: 80,
resizable: true,
sortable: false,
filter: false,
formatter: ({ row }) => {
if (_.isEmpty(row)) return "";
if (!row.ip) return "-";
const fingreprint = row.ip?.replace("::ffff:", "").split("///")[1];
if (!fingreprint) return "-";
return (
<Tooltip title={fingreprint}>
<Button
className="ellipsis"
onClick={() => {
navigator.clipboard.writeText(fingreprint);
notification.showSuccess("Успішно", "Відбиток скопійовано!");
}}
>
Скопіювати
</Button>
</Tooltip>
);
}, },
}, },
{ {

13
src/services/system/jwt.service.ts

@ -0,0 +1,13 @@
import "core-js/stable/atob";
import jwtDecode from "jwt-decode";
export function isTokenValid(token) {
try {
const decoded = jwtDecode(token);
const currentTime = Math.floor(Date.now() / 1000) + 500;
return decoded["exp"] > currentTime;
} catch (error) {
console.error("Invalid JWT token", error, token);
return false;
}
}

20
src/services/system/real-time.service.ts

@ -4,6 +4,8 @@ import { socketEvents } from "@/shared/events";
import io from "socket.io-client"; import io from "socket.io-client";
import { authService } from "../domain"; import { authService } from "../domain";
import { GlobalContainerService } from "./global-container.service"; import { GlobalContainerService } from "./global-container.service";
import { isTokenValid } from "./jwt.service";
import { UserFingerprintGenerator } from "@/shared";
const store = () => GlobalContainerService.get("store"); const store = () => GlobalContainerService.get("store");
@ -12,13 +14,16 @@ export class SocketIo {
init() { init() {
try { try {
const getTokenFn = this.getToken.bind(this);
this.socket = io(config.socketUrl, { this.socket = io(config.socketUrl, {
transports: ["websocket", "polling"], transports: ["websocket", "polling"],
reconnection: true, reconnection: true,
secure: true, secure: true,
reconnectionAttempts: 10, async auth(cb) {
auth(cb) { const accessToken = await getTokenFn();
cb({ accessToken: store()?.getState()?.auth?.accessToken }); const deviceUuid = await UserFingerprintGenerator.generateUserFingerprint();
cb({ accessToken, deviceUuid });
}, },
}); });
this._on("connect", () => { this._on("connect", () => {
@ -30,6 +35,15 @@ export class SocketIo {
} }
} }
async getToken() {
const accessToken = store()?.getState()?.auth?.accessToken;
if (isTokenValid(accessToken)) return accessToken;
await authService.refreshSession();
return store()?.getState()?.auth?.accessToken;
}
get header() { get header() {
return { return {
authorization: "Bearer " + store()?.getState()?.auth?.accessToken, authorization: "Bearer " + store()?.getState()?.auth?.accessToken,

1869
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save