mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
feat(frontend): Improve comms around authentication (#9348)
* use enum for flow authentication * fix inaccurate texts * add a better user info on login * fix test assertation
This commit is contained in:
parent
cb240e4e0f
commit
bd0dc3fe50
@ -8,7 +8,7 @@ import { ApiEndpoints } from '../enums/ApiEndpoints';
|
|||||||
import { apiUrl, useServerApiState } from '../states/ApiState';
|
import { apiUrl, useServerApiState } from '../states/ApiState';
|
||||||
import { useLocalState } from '../states/LocalState';
|
import { useLocalState } from '../states/LocalState';
|
||||||
import { useUserState } from '../states/UserState';
|
import { useUserState } from '../states/UserState';
|
||||||
import { type Provider, fetchGlobalStates } from '../states/states';
|
import { FlowEnum, type Provider, fetchGlobalStates } from '../states/states';
|
||||||
import { showLoginNotification } from './notifications';
|
import { showLoginNotification } from './notifications';
|
||||||
import { generateUrl } from './urls';
|
import { generateUrl } from './urls';
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ export const doBasicLogin = async (
|
|||||||
if (err?.response?.status == 401) {
|
if (err?.response?.status == 401) {
|
||||||
setAuthContext(err.response.data?.data);
|
setAuthContext(err.response.data?.data);
|
||||||
const mfa_flow = err.response.data.data.flows.find(
|
const mfa_flow = err.response.data.data.flows.find(
|
||||||
(flow: any) => flow.id == 'mfa_authenticate'
|
(flow: any) => flow.id == FlowEnum.MfaAuthenticate
|
||||||
);
|
);
|
||||||
if (mfa_flow && mfa_flow.is_pending == true) {
|
if (mfa_flow && mfa_flow.is_pending == true) {
|
||||||
success = true;
|
success = true;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Trans, t } from '@lingui/macro';
|
import { Trans, t } from '@lingui/macro';
|
||||||
import { Anchor, Divider, Loader, Text } from '@mantine/core';
|
import { Anchor, Divider, Group, Loader, Text } from '@mantine/core';
|
||||||
import { useToggle } from '@mantine/hooks';
|
import { useToggle } from '@mantine/hooks';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
|
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
@ -97,7 +97,12 @@ export default function Login() {
|
|||||||
<>
|
<>
|
||||||
<Wrapper titleText={t`Login`} smallPadding>
|
<Wrapper titleText={t`Login`} smallPadding>
|
||||||
{isLoggingIn ? (
|
{isLoggingIn ? (
|
||||||
|
<>
|
||||||
|
<Group justify='center'>
|
||||||
<Loader />
|
<Loader />
|
||||||
|
</Group>
|
||||||
|
<Trans>Logging you in</Trans>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<AuthenticationForm />
|
<AuthenticationForm />
|
||||||
|
@ -13,7 +13,7 @@ export default function Mfa() {
|
|||||||
const [loginError, setLoginError] = useState<string | undefined>(undefined);
|
const [loginError, setLoginError] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper titleText={t`Multi-Factor Login`} logOff>
|
<Wrapper titleText={t`Multi-Factor Authentication`} logOff>
|
||||||
<TextInput
|
<TextInput
|
||||||
required
|
required
|
||||||
label={t`TOTP Code`}
|
label={t`TOTP Code`}
|
||||||
|
@ -32,7 +32,11 @@ import { StylishText } from '../../../../components/items/StylishText';
|
|||||||
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
||||||
import { ProviderLogin, authApi } from '../../../../functions/auth';
|
import { ProviderLogin, authApi } from '../../../../functions/auth';
|
||||||
import { apiUrl, useServerApiState } from '../../../../states/ApiState';
|
import { apiUrl, useServerApiState } from '../../../../states/ApiState';
|
||||||
import type { AuthConfig, Provider } from '../../../../states/states';
|
import {
|
||||||
|
type AuthConfig,
|
||||||
|
FlowEnum,
|
||||||
|
type Provider
|
||||||
|
} from '../../../../states/states';
|
||||||
import { ApiTokenTable } from '../../../../tables/settings/ApiTokenTable';
|
import { ApiTokenTable } from '../../../../tables/settings/ApiTokenTable';
|
||||||
import { QrRegistrationForm } from './QrRegistrationForm';
|
import { QrRegistrationForm } from './QrRegistrationForm';
|
||||||
import { useReauth } from './useConfirm';
|
import { useReauth } from './useConfirm';
|
||||||
@ -660,13 +664,13 @@ async function runActionWithFallback(
|
|||||||
if (err.status == 401) {
|
if (err.status == 401) {
|
||||||
if (
|
if (
|
||||||
err.response.data.data.flows.find(
|
err.response.data.data.flows.find(
|
||||||
(flow: any) => flow.id == 'mfa_reauthenticate'
|
(flow: any) => flow.id == FlowEnum.MfaReauthenticate
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return ResultType.mfareauth;
|
return ResultType.mfareauth;
|
||||||
} else if (
|
} else if (
|
||||||
err.response.data.data.flows.find(
|
err.response.data.data.flows.find(
|
||||||
(flow: any) => flow.id == 'reauthenticate'
|
(flow: any) => flow.id == FlowEnum.Reauthenticate
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return ResultType.reauth;
|
return ResultType.reauth;
|
||||||
|
@ -64,8 +64,8 @@ export default function SystemSettings() {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'login',
|
name: 'authentication',
|
||||||
label: t`Login`,
|
label: t`Authentication`,
|
||||||
icon: <IconFingerprint />,
|
icon: <IconFingerprint />,
|
||||||
content: (
|
content: (
|
||||||
<GlobalSettingList
|
<GlobalSettingList
|
||||||
|
@ -107,7 +107,7 @@ test('Settings - Admin', async ({ page }) => {
|
|||||||
// System Settings
|
// System Settings
|
||||||
await page.locator('label').filter({ hasText: 'System Settings' }).click();
|
await page.locator('label').filter({ hasText: 'System Settings' }).click();
|
||||||
await page.getByText('Base URL', { exact: true }).waitFor();
|
await page.getByText('Base URL', { exact: true }).waitFor();
|
||||||
await loadTab(page, 'Login');
|
await loadTab(page, 'Authentication');
|
||||||
await loadTab(page, 'Barcodes');
|
await loadTab(page, 'Barcodes');
|
||||||
await loadTab(page, 'Notifications');
|
await loadTab(page, 'Notifications');
|
||||||
await loadTab(page, 'Pricing');
|
await loadTab(page, 'Pricing');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user