feat(MED-122): update current user account loader

This commit is contained in:
2025-07-10 13:19:01 +03:00
parent bbcf0b6d83
commit 0a0b1f0dee
4 changed files with 14 additions and 25 deletions

View File

@@ -1,14 +1,13 @@
import { redirect } from 'next/navigation';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
import { PageBody, PageHeader } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
import { toTitleCase } from '@/lib/utils';
import Dashboard from '../_components/dashboard';
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
export const generateMetadata = async () => {
const i18n = await createI18nServerInstance();
@@ -20,7 +19,7 @@ export const generateMetadata = async () => {
};
async function UserHomePage() {
const account = await getAccount();
const account = await loadCurrentUserAccount();
if (!account) {
redirect('/');
}
@@ -44,21 +43,4 @@ async function UserHomePage() {
);
}
async function getAccount() {
const client = getSupabaseServerClient();
const {
data: { user },
} = await client.auth.getUser();
const accountResponse = await client
.schema('medreport')
.from('accounts')
.select('name')
.eq('primary_owner_user_id', user!.id)
.single();
return accountResponse.data;
}
export default withI18n(UserHomePage);