Block WS access if Matrix account is not linked
This commit is contained in:
@@ -6,6 +6,7 @@ export interface UserInfo {
|
||||
time_update: number;
|
||||
name: string;
|
||||
email: string;
|
||||
matrix_account_connected: boolean;
|
||||
matrix_user_id?: string;
|
||||
matrix_device_id?: string;
|
||||
matrix_recovery_state?: "Enabled" | "Disabled" | "Unknown" | "Incomplete";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { NotLinkedAccountMessage } from "../widgets/NotLinkedAccountMessage";
|
||||
export function HomeRoute(): React.ReactElement {
|
||||
const user = useUserInfo();
|
||||
|
||||
if (!user.info.matrix_user_id) return <NotLinkedAccountMessage />;
|
||||
if (!user.info.matrix_account_connected) return <NotLinkedAccountMessage />;
|
||||
|
||||
return (
|
||||
<p>
|
||||
|
||||
@@ -4,7 +4,9 @@ import "react-json-view-lite/dist/index.css";
|
||||
import { WsApi, type WsMessage } from "../api/WsApi";
|
||||
import { useSnackbar } from "../hooks/contexts_provider/SnackbarProvider";
|
||||
import { time } from "../utils/DateUtils";
|
||||
import { useUserInfo } from "../widgets/dashboard/BaseAuthenticatedPage";
|
||||
import { MatrixGWRouteContainer } from "../widgets/MatrixGWRouteContainer";
|
||||
import { NotLinkedAccountMessage } from "../widgets/NotLinkedAccountMessage";
|
||||
|
||||
const State = {
|
||||
Closed: "Closed",
|
||||
@@ -15,6 +17,9 @@ const State = {
|
||||
type TimestampedMessages = WsMessage & { time: number };
|
||||
|
||||
export function WSDebugRoute(): React.ReactElement {
|
||||
const user = useUserInfo();
|
||||
if (!user.info.matrix_account_connected) return <NotLinkedAccountMessage />;
|
||||
|
||||
const snackbar = useSnackbar();
|
||||
|
||||
const [state, setState] = React.useState<string>(State.Closed);
|
||||
@@ -28,7 +33,7 @@ export function WSDebugRoute(): React.ReactElement {
|
||||
|
||||
ws.onopen = () => setState(State.Connected);
|
||||
ws.onerror = (e) => {
|
||||
console.error(`WS Debug error! ${e}`);
|
||||
console.error(`WS Debug error!`, e);
|
||||
snackbar(`WebSocket error! ${e}`);
|
||||
setState(State.Error);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useTheme } from "@mui/material/styles";
|
||||
import type {} from "@mui/material/themeCssVarsAugmentation";
|
||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||
import * as React from "react";
|
||||
import { useUserInfo } from "./BaseAuthenticatedPage";
|
||||
import DashboardSidebarContext from "./DashboardSidebarContext";
|
||||
import DashboardSidebarDividerItem from "./DashboardSidebarDividerItem";
|
||||
import DashboardSidebarPageItem from "./DashboardSidebarPageItem";
|
||||
@@ -31,6 +32,7 @@ export default function DashboardSidebar({
|
||||
container,
|
||||
}: DashboardSidebarProps) {
|
||||
const theme = useTheme();
|
||||
const user = useUserInfo();
|
||||
|
||||
const isOverSmViewport = useMediaQuery(theme.breakpoints.up("sm"));
|
||||
const isOverMdViewport = useMediaQuery(theme.breakpoints.up("md"));
|
||||
@@ -99,6 +101,7 @@ export default function DashboardSidebar({
|
||||
}}
|
||||
>
|
||||
<DashboardSidebarPageItem
|
||||
disabled={!user.info.matrix_account_connected}
|
||||
title="Messages"
|
||||
icon={<Icon path={mdiForum} size={"1.5em"} />}
|
||||
href="/"
|
||||
@@ -115,6 +118,7 @@ export default function DashboardSidebar({
|
||||
href="/tokens"
|
||||
/>
|
||||
<DashboardSidebarPageItem
|
||||
disabled={!user.info.matrix_account_connected}
|
||||
title="WS Debug"
|
||||
icon={<Icon path={mdiBug} size={"1.5em"} />}
|
||||
href="/wsdebug"
|
||||
@@ -123,7 +127,12 @@ export default function DashboardSidebar({
|
||||
</Box>
|
||||
</React.Fragment>
|
||||
),
|
||||
[mini, hasDrawerTransitions, isFullyExpanded]
|
||||
[
|
||||
mini,
|
||||
hasDrawerTransitions,
|
||||
isFullyExpanded,
|
||||
user.info.matrix_account_connected,
|
||||
]
|
||||
);
|
||||
|
||||
const getDrawerSharedSx = React.useCallback(
|
||||
|
||||
Reference in New Issue
Block a user