diff --git a/.env b/.env index 9662893..cfb68d2 100644 --- a/.env +++ b/.env @@ -86,6 +86,7 @@ LIMITED_FEATURES=false LIMIT_MAX_WATCHLIST=0 LIMIT_MAX_WATCHLIST_DOMAINS=0 LIMIT_MAX_WATCHLIST_WEBHOOKS=0 +PUBLIC_RDAP_LOOKUP_ENABLE=false # STATISTICS INFLUXDB_ENABLED=false diff --git a/assets/App.tsx b/assets/App.tsx index e7d9abc..1f6fe05 100644 --- a/assets/App.tsx +++ b/assets/App.tsx @@ -1,4 +1,4 @@ -import {Button, ConfigProvider, Drawer, Flex, Layout, theme, Typography} from 'antd' +import {Button, ConfigProvider, Drawer, Flex, Layout, message, theme, Typography} from 'antd' import {Link, Navigate, Route, Routes, useLocation, useNavigate} from 'react-router-dom' import TextPage from './pages/TextPage' import DomainSearchPage from './pages/search/DomainSearchPage' @@ -9,8 +9,8 @@ import WatchlistPage from './pages/tracking/WatchlistPage' import UserPage from './pages/UserPage' import type {PropsWithChildren} from 'react' import React, { useCallback, useEffect, useMemo, useState} from 'react' -import {getUser} from './utils/api' -import LoginPage, {AuthenticatedContext} from './pages/LoginPage' +import {getConfiguration, getUser, type InstanceConfig} from './utils/api' +import LoginPage from './pages/LoginPage' import ConnectorPage from './pages/tracking/ConnectorPage' import NotFoundPage from './pages/NotFoundPage' import useBreakpoint from './hooks/useBreakpoint' @@ -19,12 +19,14 @@ import {jt, t} from 'ttag' import {MenuOutlined} from '@ant-design/icons' import TrackedDomainPage from './pages/tracking/TrackedDomainPage' import IcannRegistrarPage from "./pages/infrastructure/IcannRegistrarPage" +import type {AuthContextType} from "./contexts" +import {AuthenticatedContext, ConfigurationContext} from "./contexts" const PROJECT_LINK = 'https://github.com/maelgangloff/domain-watchdog' const LICENSE_LINK = 'https://www.gnu.org/licenses/agpl-3.0.txt' const ProjectLink = Domain Watchdog -const LicenseLink = AGPL-3.0-or-later +const LicenseLink = AGPL-3.0-or-later function SiderWrapper(props: PropsWithChildren<{sidebarCollapsed: boolean, setSidebarCollapsed: (collapsed: boolean) => void}>): React.ReactElement { const {sidebarCollapsed, setSidebarCollapsed, children} = props @@ -68,18 +70,22 @@ export default function App(): React.ReactElement { const [sidebarCollapsed, setSidebarCollapsed] = useState(false) const [isAuthenticated, setIsAuthenticated] = useState(false) - const authenticated = useCallback((authenticated: boolean) => { - setIsAuthenticated(authenticated) - }, []) - - const contextValue = useMemo(() => ({ - authenticated, - setIsAuthenticated - }), [authenticated, setIsAuthenticated]) + const [configuration, setConfiguration] = useState(undefined) const [darkMode, setDarkMode] = useState(false) - const windowQuery = window.matchMedia('(prefers-color-scheme:dark)') + const [messageApi, contextHolder] = message.useMessage() + + + const authContextValue: AuthContextType = useMemo(() => ({ + isAuthenticated, + setIsAuthenticated + }), [isAuthenticated]) + + const configContextValue = useMemo(() => ({ + configuration, + }), [configuration]) + const darkModeChange = useCallback((event: MediaQueryListEvent) => { setDarkMode(event.matches) }, []) @@ -93,14 +99,19 @@ export default function App(): React.ReactElement { useEffect(() => { setDarkMode(windowQuery.matches) - getUser().then(() => { - setIsAuthenticated(true) - if (location.pathname === '/login') navigate('/home') - }).catch(() => { - setIsAuthenticated(false) - const pathname = location.pathname - if (!['/login', '/tos', '/faq', '/privacy'].includes(pathname)) navigate('/home') - }) + getConfiguration().then(configuration => { + setConfiguration(configuration) + + getUser().then(() => { + setIsAuthenticated(true) + if (location.pathname === '/login') navigate('/home') + }).catch(() => { + setIsAuthenticated(false) + const pathname = location.pathname + if(configuration.publicRdapLookupEnabled) return navigate('/search/domain') + if (!['/login', '/tos', '/faq', '/privacy'].includes(pathname)) return navigate('/home') + }) + }).catch(() => messageApi.error(t`Unable to contact the server, please reload the page.`)) }, []) return ( @@ -109,10 +120,11 @@ export default function App(): React.ReactElement { algorithm: darkMode ? theme.darkAlgorithm : undefined }} > - + + - + @@ -128,8 +140,9 @@ export default function App(): React.ReactElement { minHeight: 360 }} > + {contextHolder} - }/> + }/> }/> }/> @@ -158,8 +171,8 @@ export default function App(): React.ReactElement { - - + + + ) } diff --git a/assets/components/LoginForm.tsx b/assets/components/LoginForm.tsx index 966353f..c78496b 100644 --- a/assets/components/LoginForm.tsx +++ b/assets/components/LoginForm.tsx @@ -2,10 +2,10 @@ import {Button, Flex, Form, Input, message} from 'antd' import {t} from 'ttag' import React, {useContext, useEffect, useState} from 'react' import {getUser, login} from '../utils/api' -import {AuthenticatedContext} from '../pages/LoginPage' import {useNavigate} from 'react-router-dom' import {showErrorAPI} from '../utils/functions/showErrorAPI' +import {AuthenticatedContext} from "../contexts" interface FieldType { username: string @@ -66,9 +66,9 @@ export function LoginForm({ssoLogin}: { ssoLogin?: boolean }) { - + {ssoLogin &&