Files
myeasycms-v2/apps/web/app/join/page.tsx
giancarlo 7579ee9a2c Refactor authentication flow and improve code organization
The update implemented a redirect functionality in the multi-factor authentication flow for a better user experience. It also involved a refactoring of some parts of the code, substituting direct routing paths with path configs for easier future modifications. Import statements were adjusted for better code organization and readability.
2024-03-27 15:07:15 +08:00

47 lines
1.0 KiB
TypeScript

import { notFound } from 'next/navigation';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import { withI18n } from '~/lib/i18n/with-i18n';
interface Context {
searchParams: {
invite_token: string;
};
}
export const metadata = {
title: `Join Organization`,
};
async function JoinTeamAccountPage({ searchParams }: Context) {
const token = searchParams.invite_token;
const data = await getInviteDataFromInviteToken(token);
if (!data) {
notFound();
}
return <></>;
}
export default withI18n(JoinTeamAccountPage);
async function getInviteDataFromInviteToken(token: string) {
// we use an admin client to be able to read the pending membership
// without having to be logged in
const adminClient = getSupabaseServerComponentClient({ admin: true });
const { data: invitation, error } = await adminClient
.from('invitations')
.select()
.eq('invite_token', token)
.single();
if (!invitation ?? error) {
return null;
}
return invitation;
}