* chore(version): bump version to 2.12.1 and update auth middleware to use getClaims instead of getUser - Incremented version in package.json from 2.12.0 to 2.12.1. - Refactored middleware to replace supabase.auth.getUser() with supabase.auth.getClaims() for improved claims handling. - Updated user checks in middleware to validate claims instead of user object. * refactor(middleware): update user authentication to utilize getClaims for improved claims validation - Replaced calls to supabase.auth.getUser() with supabase.auth.getClaims() in middleware for better claims handling. - Adjusted user validation checks to ensure claims are used instead of the user object, enhancing security and consistency in authentication flow. * refactor(auth): update VerifyPage to use getClaims for user validation - Replaced the use of supabase.auth.getUser() with supabase.auth.getClaims() in the VerifyPage component for improved claims handling. - Adjusted user validation logic to check for claims instead of the user object, enhancing security and consistency in the authentication flow.
54 lines
1.3 KiB
TypeScript
54 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 { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
|
|
import pathsConfig from '~/config/paths.config';
|
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
|
|
interface Props {
|
|
searchParams: Promise<{
|
|
next?: string;
|
|
}>;
|
|
}
|
|
|
|
export const generateMetadata = async () => {
|
|
const i18n = await createI18nServerInstance();
|
|
|
|
return {
|
|
title: i18n.t('auth:signIn'),
|
|
};
|
|
};
|
|
|
|
async function VerifyPage(props: Props) {
|
|
const client = getSupabaseServerClient();
|
|
|
|
const { data } = await client.auth.getClaims();
|
|
|
|
if (!data?.claims) {
|
|
redirect(pathsConfig.auth.signIn);
|
|
}
|
|
|
|
const needsMfa = await checkRequiresMultiFactorAuthentication(client);
|
|
|
|
if (!needsMfa) {
|
|
redirect(pathsConfig.auth.signIn);
|
|
}
|
|
|
|
const nextPath = (await props.searchParams).next;
|
|
const redirectPath = nextPath ?? pathsConfig.app.home;
|
|
|
|
return (
|
|
<MultiFactorChallengeContainer
|
|
userId={data.claims.sub}
|
|
paths={{
|
|
redirectPath,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default withI18n(VerifyPage);
|