mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-19 07:55:25 +02:00
feat: Add get has 2fa enabled
This commit is contained in:
parent
516bdc4d2b
commit
31288c9e79
@ -286,8 +286,12 @@
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
"enable2fa": "2-Factor-Authentication",
|
||||
"enable2fa": "Two-Factor-Authentication",
|
||||
"aliasPreferences": "Alias Preferences"
|
||||
},
|
||||
"2fa": {
|
||||
"title": "Two-Factor-Authentication",
|
||||
"alreadyEnabled": "You have successfully enabled 2FA!"
|
||||
}
|
||||
},
|
||||
"LogoutRoute": {
|
||||
|
@ -27,6 +27,7 @@ import ReportsRoute from "~/routes/ReportsRoute"
|
||||
import ReservedAliasDetailRoute from "~/routes/ReservedAliasDetailRoute"
|
||||
import ReservedAliasesRoute from "~/routes/ReservedAliasesRoute"
|
||||
import RootRoute from "~/routes/Root"
|
||||
import Settings2FARoute from "~/routes/Settings2FARoute"
|
||||
import SettingsAliasPreferencesRoute from "~/routes/SettingsAliasPreferencesRoute"
|
||||
import SettingsRoute from "~/routes/SettingsRoute"
|
||||
import SignupRoute from "~/routes/SignupRoute"
|
||||
@ -96,6 +97,10 @@ const router = createBrowserRouter([
|
||||
path: "/settings/alias-preferences",
|
||||
element: <SettingsAliasPreferencesRoute />,
|
||||
},
|
||||
{
|
||||
path: "/settings/2fa",
|
||||
element: <Settings2FARoute />,
|
||||
},
|
||||
{
|
||||
path: "/reports",
|
||||
loader: getServerSettings,
|
||||
|
9
src/apis/get-has-2fa-enabled.ts
Normal file
9
src/apis/get-has-2fa-enabled.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import {client} from "~/constants/axios-client"
|
||||
|
||||
export default async function getHas2FAEnabled(): Promise<boolean> {
|
||||
const {data} = await client.get(`${import.meta.env.VITE_SERVER_BASE_URL}/v1/setup-otp/`, {
|
||||
withCredentials: true,
|
||||
})
|
||||
|
||||
return data.enabled
|
||||
}
|
32
src/routes/Settings2FARoute.tsx
Normal file
32
src/routes/Settings2FARoute.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import {ReactElement} from "react"
|
||||
import {AxiosError} from "axios"
|
||||
import {useTranslation} from "react-i18next"
|
||||
|
||||
import {useQuery} from "@tanstack/react-query"
|
||||
import {Alert} from "@mui/material"
|
||||
|
||||
import {QueryResult, SimplePageBuilder} from "~/components"
|
||||
import getHas2FAEnabled from "~/apis/get-has-2fa-enabled"
|
||||
|
||||
export default function Settings2FARoute(): ReactElement {
|
||||
const {t} = useTranslation()
|
||||
const query = useQuery<boolean, AxiosError>(["get_2fa_enabled"], getHas2FAEnabled)
|
||||
|
||||
return (
|
||||
<SimplePageBuilder.Page title={t("routes.SettingsRoute.2fa.title")}>
|
||||
<QueryResult<boolean, AxiosError> query={query}>
|
||||
{has2FAEnabled =>
|
||||
has2FAEnabled ? (
|
||||
<>
|
||||
<Alert severity="success">
|
||||
{t("routes.SettingsRoute.2fa.alreadyEnabled")}
|
||||
</Alert>
|
||||
</>
|
||||
) : (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
</QueryResult>
|
||||
</SimplePageBuilder.Page>
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user