Files
myeasycms-v2/apps/web/app/auth/verify/page.tsx
giancarlo cbf116c688 Add user id parameter to multi-factor authentication functions
The multi-factor authentication functions have been modified to accept a user id as a parameter. This provides more flexibility as it allows a more specific targeting of users. The `useFetchAuthFactors` function has been updated to export the function rather than default, and the `useFactorsMutationKey` function has been updated to take a user id.
2024-05-28 21:13:36 +07:00

52 lines
1.3 KiB
TypeScript

import { redirect } from 'next/navigation';
import { MultiFactorChallengeContainer } from '@kit/auth/mfa';
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
import { requireUser } from '@kit/supabase/require-user';
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;
const auth = await requireUser(client);
if (auth.error) {
redirect(auth.redirectTo);
}
return (
<MultiFactorChallengeContainer
userId={auth.data.id}
paths={{
redirectPath,
}}
/>
);
}
export default withI18n(VerifyPage);