mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add instance config endpoint
This commit is contained in:
@@ -48,7 +48,7 @@ export default function App() {
|
||||
if (location.pathname === '/login') navigate('/home')
|
||||
}).catch(() => {
|
||||
setIsAuthenticated(false)
|
||||
navigate('/home')
|
||||
if (location.pathname !== '/login') navigate('/home')
|
||||
})
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, {createContext, useContext, useEffect, useState} from "react";
|
||||
import {Alert, Button, Card, Flex, Form, Input} from "antd";
|
||||
import {getUser, login} from "../utils/api";
|
||||
import {getConfiguration, getUser, InstanceConfig, login} from "../utils/api";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import {t} from 'ttag'
|
||||
|
||||
@@ -13,7 +13,8 @@ export const AuthenticatedContext = createContext<any>(null)
|
||||
|
||||
export default function LoginPage() {
|
||||
|
||||
const [error, setError] = useState()
|
||||
const [error, setError] = useState<string>()
|
||||
const [configuration, setConfiguration] = useState<InstanceConfig>()
|
||||
const navigate = useNavigate()
|
||||
const {setIsAuthenticated} = useContext(AuthenticatedContext)
|
||||
|
||||
@@ -32,6 +33,7 @@ export default function LoginPage() {
|
||||
setIsAuthenticated(true)
|
||||
navigate('/home')
|
||||
})
|
||||
getConfiguration().then(setConfiguration)
|
||||
}, [])
|
||||
|
||||
return <Flex gap="middle" align="center" justify="center" vertical><Card
|
||||
@@ -75,11 +77,11 @@ export default function LoginPage() {
|
||||
{t`Submit`}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
<Form.Item wrapperCol={{offset: 8, span: 16}}>
|
||||
{configuration?.ssoLogin && <Form.Item wrapperCol={{offset: 8, span: 16}}>
|
||||
<Button type="primary" htmlType="button" href="/login/oauth">
|
||||
{t`Log in with SSO`}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form.Item>}
|
||||
</Form>
|
||||
</Card>
|
||||
</Flex>
|
||||
|
||||
@@ -71,6 +71,11 @@ export interface Watchlist {
|
||||
connector?: string
|
||||
}
|
||||
|
||||
export interface InstanceConfig {
|
||||
ssoLogin: boolean
|
||||
limtedFeatures: boolean
|
||||
}
|
||||
|
||||
export async function request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig): Promise<R> {
|
||||
const axiosConfig: AxiosRequestConfig = {
|
||||
...config,
|
||||
@@ -84,6 +89,7 @@ export async function request<T = any, R = AxiosResponse<T>, D = any>(config: Ax
|
||||
return await axios.request<T, R, D>(axiosConfig)
|
||||
}
|
||||
|
||||
|
||||
export * from './domain'
|
||||
export * from './tld'
|
||||
export * from './user'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {request, User} from "./index";
|
||||
import {InstanceConfig, request, User} from "./index";
|
||||
|
||||
|
||||
export async function login(email: string, password: string): Promise<boolean> {
|
||||
@@ -16,3 +16,10 @@ export async function getUser(): Promise<User> {
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
|
||||
export async function getConfiguration(): Promise<InstanceConfig> {
|
||||
const response = await request<InstanceConfig>({
|
||||
url: 'config'
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
Reference in New Issue
Block a user