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.
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { redirect } from 'next/navigation';
|
|
|
|
import { MultiFactorChallengeContainer } from '@kit/auth/mfa';
|
|
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
|
|
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
|
|
|
import pathsConfig from '~/config/paths.config';
|
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
|
|
interface Props {
|
|
searchParams: {
|
|
next?: string;
|
|
};
|
|
}
|
|
|
|
export const generateMetadata = async () => {
|
|
const i18n = await createI18nServerInstance();
|
|
|
|
return {
|
|
title: i18n.t('auth:signIn'),
|
|
};
|
|
};
|
|
|
|
async function VerifyPage(props: Props) {
|
|
const client = getSupabaseServerComponentClient();
|
|
const needsMfa = await checkRequiresMultiFactorAuthentication(client);
|
|
|
|
if (!needsMfa) {
|
|
redirect(pathsConfig.auth.signIn);
|
|
}
|
|
|
|
const redirectPath = props.searchParams.next ?? pathsConfig.app.home;
|
|
|
|
return (
|
|
<MultiFactorChallengeContainer
|
|
paths={{
|
|
redirectPath,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default withI18n(VerifyPage);
|