From 91bc511b2de1158ce0bed0a822d3a439d95a1b47 Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Wed, 15 Jun 2022 16:14:11 +0200 Subject: [PATCH] feat: enforce accessing only existing chats --- packages/status-react/src/routes/index.tsx | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/status-react/src/routes/index.tsx b/packages/status-react/src/routes/index.tsx index f365522f..ee418bb2 100644 --- a/packages/status-react/src/routes/index.tsx +++ b/packages/status-react/src/routes/index.tsx @@ -1,12 +1,18 @@ import React from 'react' -import { BrowserRouter, Route, Routes } from 'react-router-dom' +import { + BrowserRouter, + Navigate, + Route, + Routes, + useMatch, +} from 'react-router-dom' import { MainSidebar } from '~/src/components/main-sidebar' import { AppProvider } from '~/src/contexts/app-context' import { DialogProvider } from '~/src/contexts/dialog-context' import { ThemeProvider } from '~/src/contexts/theme-context' -import { ProtocolProvider } from '~/src/protocol' +import { ProtocolProvider, useProtocol } from '~/src/protocol' import { Chat } from '~/src/routes/chat' import { styled } from '~/src/styles/config' import { GlobalStyle } from '~/src/styles/GlobalStyle' @@ -17,6 +23,24 @@ interface Props extends Config { meta?: string } +// TODO: use a better way to handle this +const Gate = (props: { children: JSX.Element }) => { + const { client } = useProtocol() + + const { params } = useMatch(':id')! + const chatId = params.id! + + const chat = client.community.getChat(chatId) + + if (!chat) { + return ( + + ) + } + + return props.children +} + export const Community = (props: Props) => { const { theme, router: Router = BrowserRouter } = props @@ -30,7 +54,14 @@ export const Community = (props: Props) => { - } /> + + + + } + />