mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 19:28:33 +00:00
Added notifications to 2FA and fixed state
This commit is contained in:
@@ -60,6 +60,7 @@ export default function MFAStep({
|
|||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isLoadingResend, setIsLoadingResend] = useState(false);
|
||||||
const [mfaCode, setMfaCode] = useState('');
|
const [mfaCode, setMfaCode] = useState('');
|
||||||
const [triesLeft, setTriesLeft] = useState<number | undefined>(undefined);
|
const [triesLeft, setTriesLeft] = useState<number | undefined>(undefined);
|
||||||
|
|
||||||
@@ -103,9 +104,12 @@ export default function MFAStep({
|
|||||||
|
|
||||||
const handleResendMfaCode = async () => {
|
const handleResendMfaCode = async () => {
|
||||||
try {
|
try {
|
||||||
|
setIsLoadingResend(true);
|
||||||
await sendMfaToken.mutateAsync({ email });
|
await sendMfaToken.mutateAsync({ email });
|
||||||
|
setIsLoadingResend(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
setIsLoadingResend(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,13 +141,13 @@ export default function MFAStep({
|
|||||||
<span className="text-bunker-400">{t('mfa:step2-resend-alert')}</span>
|
<span className="text-bunker-400">{t('mfa:step2-resend-alert')}</span>
|
||||||
<u
|
<u
|
||||||
className={`font-normal ${
|
className={`font-normal ${
|
||||||
isLoading
|
isLoadingResend
|
||||||
? 'text-bunker-400'
|
? 'text-bunker-400'
|
||||||
: 'text-primary-700 hover:text-primary duration-200'
|
: 'text-primary-700 hover:text-primary duration-200'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button disabled={isLoading} onClick={() => handleResendMfaCode()} type="button">
|
<button disabled={isLoading} onClick={() => handleResendMfaCode()} type="button">
|
||||||
{isLoading
|
{isLoadingResend
|
||||||
? t('mfa:step2-resend-progress')
|
? t('mfa:step2-resend-progress')
|
||||||
: t('mfa:step2-resend-submit')}
|
: t('mfa:step2-resend-submit')}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
+12
-1
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
|
||||||
import { Checkbox } from '@app/components/v2';
|
import { Checkbox } from '@app/components/v2';
|
||||||
|
|
||||||
import { useGetUser } from '../../../../hooks/api';
|
import { useGetUser } from '../../../../hooks/api';
|
||||||
@@ -9,6 +10,7 @@ import updateMyMfaEnabled from '../../../../pages/api/user/updateMyMfaEnabled';
|
|||||||
export const SecuritySection = () => {
|
export const SecuritySection = () => {
|
||||||
const [isMfaEnabled, setIsMfaEnabled] = useState(false);
|
const [isMfaEnabled, setIsMfaEnabled] = useState(false);
|
||||||
const { data: user } = useGetUser();
|
const { data: user } = useGetUser();
|
||||||
|
const { createNotification } = useNotificationContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user && typeof user.isMfaEnabled !== 'undefined') {
|
if (user && typeof user.isMfaEnabled !== 'undefined') {
|
||||||
@@ -25,14 +27,23 @@ export const SecuritySection = () => {
|
|||||||
if (newUser) {
|
if (newUser) {
|
||||||
setIsMfaEnabled(newUser.isMfaEnabled);
|
setIsMfaEnabled(newUser.isMfaEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: `${newUser.isMfaEnabled ? 'Successfully turned on two-factor authentication.' : 'Successfully turned off two-factor authentication.'}`,
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
createNotification({
|
||||||
|
text: 'Something went wrong while toggling the two-factor authentication.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
<div className="mb-6 mt-4 flex w-full flex-col items-start rounded-md bg-white/5 px-6 pb-6 pt-2">
|
<div className="mb-6 mt-2 flex w-full flex-col items-start rounded-md bg-white/5 px-6 pb-6 pt-2">
|
||||||
<p className="mb-4 mt-2 text-xl font-semibold">
|
<p className="mb-4 mt-2 text-xl font-semibold">
|
||||||
Two-factor Authentication
|
Two-factor Authentication
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user