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:
@@ -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,
|
||||
Reference in New Issue
Block a user