This commit updates the 'next' package from version 14.2.0 to 14.2.1 across various modules. It also refactors the code for user account handling to make it controlled by an enableTeamAccounts flag in the featureFlagsConfig, essentially allowing the enabling or disabling of the 'team accounts' feature according to the specified flag.
40 lines
1004 B
TypeScript
40 lines
1004 B
TypeScript
import { cache } from 'react';
|
|
|
|
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
|
|
|
import featureFlagsConfig from '~/config/feature-flags.config';
|
|
import { Database } from '~/lib/database.types';
|
|
|
|
export const loadUserWorkspace = cache(async () => {
|
|
const client = getSupabaseServerComponentClient();
|
|
const loadAccounts = featureFlagsConfig.enableTeamAccounts;
|
|
|
|
const accounts = loadAccounts ? await loadUserAccounts(client) : [];
|
|
const { data } = await client.auth.getSession();
|
|
|
|
return {
|
|
accounts,
|
|
session: data.session,
|
|
};
|
|
});
|
|
|
|
async function loadUserAccounts(
|
|
client: ReturnType<typeof getSupabaseServerComponentClient<Database>>,
|
|
) {
|
|
const { data: accounts, error } = await client
|
|
.from('user_accounts')
|
|
.select(`name, slug, picture_url`);
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
return accounts.map(({ name, slug, picture_url }) => {
|
|
return {
|
|
label: name,
|
|
value: slug,
|
|
image: picture_url,
|
|
};
|
|
});
|
|
}
|