mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: allow unauthenticated users to perform domain name lookups
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
import React, {createContext, useEffect, useState} from 'react'
|
||||
import React, { useContext, useEffect, useState} from 'react'
|
||||
import {Button, Card} from 'antd'
|
||||
import {t} from 'ttag'
|
||||
import TextPage from './TextPage'
|
||||
import {LoginForm} from '../components/LoginForm'
|
||||
import type { InstanceConfig} from '../utils/api'
|
||||
import {getConfiguration} from '../utils/api'
|
||||
import {RegisterForm} from '../components/RegisterForm'
|
||||
import useBreakpoint from "../hooks/useBreakpoint"
|
||||
|
||||
export const AuthenticatedContext = createContext<
|
||||
{
|
||||
authenticated: (authenticated: boolean) => void
|
||||
setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>
|
||||
}
|
||||
>({
|
||||
authenticated: () => {
|
||||
},
|
||||
setIsAuthenticated: () => {
|
||||
}
|
||||
})
|
||||
import {ConfigurationContext} from "../contexts"
|
||||
|
||||
export default function LoginPage() {
|
||||
const [wantRegister, setWantRegister] = useState<boolean>(false)
|
||||
const [configuration, setConfiguration] = useState<InstanceConfig>()
|
||||
const { configuration } = useContext(ConfigurationContext)
|
||||
|
||||
const md = useBreakpoint('md')
|
||||
|
||||
const toggleWantRegister = () => {
|
||||
@@ -30,14 +18,11 @@ export default function LoginPage() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getConfiguration().then((configuration) => {
|
||||
if(!configuration.registerEnabled && configuration.ssoLogin && configuration.ssoAutoRedirect) {
|
||||
window.location.href = '/login/oauth'
|
||||
return
|
||||
}
|
||||
setConfiguration(configuration)
|
||||
})
|
||||
}, [])
|
||||
if(!configuration?.registerEnabled && configuration?.ssoLogin && configuration?.ssoAutoRedirect) {
|
||||
window.location.href = '/login/oauth'
|
||||
return
|
||||
}
|
||||
}, [configuration])
|
||||
|
||||
const grid = [
|
||||
<Card.Grid key="form" style={{width: md ? '100%' : '50%', textAlign: 'center'}} hoverable={false}>
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import React, {useEffect, useState} from 'react'
|
||||
import type { FormProps} from 'antd'
|
||||
import {FloatButton} from 'antd'
|
||||
import {Empty, Flex, message, Skeleton} from 'antd'
|
||||
import React, {useContext, useEffect, useState} from 'react'
|
||||
import type {FormProps} from 'antd'
|
||||
import {Empty, Flex, FloatButton, message, Skeleton} from 'antd'
|
||||
import type {Domain, Watchlist} from '../../utils/api'
|
||||
import {addDomainToWatchlist} from '../../utils/api'
|
||||
import {getDomain} from '../../utils/api'
|
||||
import {addDomainToWatchlist, getDomain} from '../../utils/api'
|
||||
import type {AxiosError} from 'axios'
|
||||
import {t} from 'ttag'
|
||||
import type { FieldType} from '../../components/search/DomainSearchBar'
|
||||
import type {FieldType} from '../../components/search/DomainSearchBar'
|
||||
import {DomainSearchBar} from '../../components/search/DomainSearchBar'
|
||||
import {DomainResult} from '../../components/search/DomainResult'
|
||||
import {showErrorAPI} from '../../utils/functions/showErrorAPI'
|
||||
import {useNavigate, useParams} from 'react-router-dom'
|
||||
import {PlusOutlined} from '@ant-design/icons'
|
||||
import WatchlistSelectionModal from '../../components/tracking/watchlist/WatchlistSelectionModal'
|
||||
import {AuthenticatedContext} from "../../contexts"
|
||||
|
||||
export default function DomainSearchPage() {
|
||||
const {query} = useParams()
|
||||
@@ -21,6 +20,8 @@ export default function DomainSearchPage() {
|
||||
const domainLdhName = domain?.ldhName
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [addToWatchlistModal, setAddToWatchlistModal] = useState(false)
|
||||
const {isAuthenticated} = useContext(AuthenticatedContext)
|
||||
|
||||
|
||||
const [messageApi, contextHolder] = message.useMessage()
|
||||
const navigate = useNavigate()
|
||||
@@ -72,7 +73,7 @@ export default function DomainSearchPage() {
|
||||
}
|
||||
</Skeleton>
|
||||
</Flex>
|
||||
{domain
|
||||
{domain && isAuthenticated
|
||||
&& <FloatButton
|
||||
style={{
|
||||
position: 'fixed',
|
||||
@@ -94,7 +95,7 @@ export default function DomainSearchPage() {
|
||||
onClose: () => setAddToWatchlistModal(false),
|
||||
cancelText: t`Cancel`,
|
||||
okText: t`Add`
|
||||
}}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user