Implement redirect control in multi-factor auth container

The update adds a rerouting functionality upon successful multi-factor authentication, replacing a console log action previously triggered upon success. The change enhances the authentication flow by redirecting users to a specified path upon validation. Additionally, minor refactorings are done such as replacing direct routing paths with path configs and adjusting import statements.
This commit is contained in:
giancarlo
2024-03-27 14:30:23 +08:00
parent 2acd9c7d10
commit f0883c19ef
5 changed files with 34 additions and 17 deletions

View File

@@ -3,6 +3,8 @@
import type { FormEventHandler } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useMutation } from '@tanstack/react-query';
import useFetchAuthFactors from '@kit/supabase/hooks/use-fetch-mfa-factors';
@@ -17,14 +19,22 @@ import Spinner from '@kit/ui/spinner';
import { Trans } from '@kit/ui/trans';
export function MultiFactorChallengeContainer({
onSuccess,
paths,
}: React.PropsWithChildren<{
onSuccess: () => void;
paths: {
redirectPath: string;
};
}>) {
const router = useRouter();
const [factorId, setFactorId] = useState('');
const [verifyCode, setVerifyCode] = useState('');
const verifyMFAChallenge = useVerifyMFAChallenge();
const onSuccess = useCallback(() => {
router.replace(paths.redirectPath);
}, [router, paths.redirectPath]);
const onSubmitClicked: FormEventHandler<HTMLFormElement> = useCallback(
(event) => {
void (async () => {

View File

@@ -2,8 +2,7 @@
import type { Provider } from '@supabase/supabase-js';
import { isBrowser } from '@supabase/ssr';
import { isBrowser } from '@kit/shared/utils';
import { Divider } from '@kit/ui/divider';
import { If } from '@kit/ui/if';