From 5b49667797e7c8d45605d9b934d30abdf8bf2569 Mon Sep 17 00:00:00 2001 From: Matthias Mair <code@mjmair.com> Date: Sun, 29 Dec 2024 01:00:47 +0100 Subject: [PATCH] add mfa listing use build-in forms --- src/frontend/src/enums/ApiEndpoints.tsx | 1 + .../AccountSettings/SecurityContent.tsx | 29 ++++++++----------- src/frontend/src/states/ApiState.tsx | 8 ++--- src/frontend/src/states/states.tsx | 20 +++++++++++++ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/frontend/src/enums/ApiEndpoints.tsx b/src/frontend/src/enums/ApiEndpoints.tsx index 1fa858f054..23231f6ee4 100644 --- a/src/frontend/src/enums/ApiEndpoints.tsx +++ b/src/frontend/src/enums/ApiEndpoints.tsx @@ -50,6 +50,7 @@ export enum ApiEndpoints { icons = 'icons/', selectionlist_list = 'selection/', selectionlist_detail = 'selection/:id/', + securtiy_settings = '_allauth/app/v1/config', // Barcode API endpoints barcode = 'barcode/', diff --git a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx index 09ab73141a..ce7aa1b533 100644 --- a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +++ b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx @@ -68,24 +68,19 @@ export function SecurityContent() { <Title order={5}> <Trans>Multifactor</Trans> </Title> - {isLoadingProvider ? ( - <Loader /> + + {isMfaEnabled ? ( + <MfaContent /> ) : ( - <> - {isMfaEnabled ? ( - <MfaContent /> - ) : ( - <Alert - icon={<IconAlertCircle size='1rem' />} - title={t`Not enabled`} - color='yellow' - > - <Trans> - Multifactor authentication is not configured for your account{' '} - </Trans> - </Alert> - )} - </> + <Alert + icon={<IconAlertCircle size='1rem' />} + title={t`Not enabled`} + color='yellow' + > + <Trans> + Multifactor authentication is not configured for your account{' '} + </Trans> + </Alert> )} <Title order={5}> diff --git a/src/frontend/src/states/ApiState.tsx b/src/frontend/src/states/ApiState.tsx index 6043111261..82989dd137 100644 --- a/src/frontend/src/states/ApiState.tsx +++ b/src/frontend/src/states/ApiState.tsx @@ -4,13 +4,13 @@ import { createJSONStorage, persist } from 'zustand/middleware'; import { api } from '../App'; import { emptyServerAPI } from '../defaults/defaults'; import { ApiEndpoints } from '../enums/ApiEndpoints'; -import type { AuthProps, ServerAPIProps } from './states'; +import type { SecuritySetting, ServerAPIProps } from './states'; interface ServerApiStateProps { server: ServerAPIProps; setServer: (newServer: ServerAPIProps) => void; fetchServerApiState: () => void; - auth_settings?: AuthProps; + auth_settings?: SecuritySetting; } export const useServerApiState = create<ServerApiStateProps>()( @@ -31,11 +31,11 @@ export const useServerApiState = create<ServerApiStateProps>()( // Fetch login/SSO behaviour await api - .get(apiUrl(ApiEndpoints.sso_providers), { + .get(apiUrl(ApiEndpoints.securtiy_settings), { headers: { Authorization: '' } }) .then((response) => { - set({ auth_settings: response.data }); + set({ auth_settings: response.data.data }); }) .catch(() => { console.error('ERR: Error fetching SSO information'); diff --git a/src/frontend/src/states/states.tsx b/src/frontend/src/states/states.tsx index e0ca580930..47f0df3de5 100644 --- a/src/frontend/src/states/states.tsx +++ b/src/frontend/src/states/states.tsx @@ -59,6 +59,26 @@ export interface AuthProps { password_forgotten_enabled: boolean; } +export interface SecuritySetting { + account: { + authentication_method: string; + }; + socialaccount: { providers: Provider[] }; + mfa: { + supported_types: string[]; + }; + usersessions: { + track_activity: boolean; + }; +} + +export interface Provider { + id: string; + name: string; + flows: string[]; + client_id: string; +} + export interface Provider { id: string; name: string;