Refactor account handling to improve performance

This commit dates the transition from a global user session to individual account handling based on user ID. The transition was made across several components, notably the account settings, icons, and selector. This change improves performance by reducing unnecessary requests and ensures more accurate data handling. The commit also includes some cleanups and minor fixes spread across different components.
This commit is contained in:
giancarlo
2024-05-10 20:33:05 +07:00
parent 6b3b3cb58b
commit 39e0a229b6
24 changed files with 106 additions and 106 deletions

View File

@@ -1,6 +1,9 @@
import { cache } from 'react';
import { redirect } from 'next/navigation';
import { createAccountsApi } from '@kit/accounts/api';
import { requireUser } from '@kit/supabase/require-user';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import featureFlagsConfig from '~/config/feature-flags.config';
@@ -24,20 +27,19 @@ export const loadUserWorkspace = cache(async () => {
: () => Promise.resolve([]);
const workspacePromise = api.getAccountWorkspace();
const userPromise = client.auth.getUser();
const [accounts, workspace, userResult] = await Promise.all([
const [accounts, workspace, auth] = await Promise.all([
accountsPromise(),
workspacePromise,
userPromise,
requireUser(client),
]);
const user = userResult.data.user;
if (!user) {
throw new Error('User is not logged in');
if (!auth.data) {
return redirect(auth.redirectTo);
}
const user = auth.data;
return {
accounts,
workspace,